fork download
  1. class Ideone {
  2.  
  3. public static void main(String args[]) {
  4. final Student s1 = new Student(1000, "John", "Male", 18, 2234567890L, 3.8, 'B');
  5. final Student s2 = new Student(1001, "Indresh", "Male", 20, 2234567893L, 4.0, 'C', true);
  6. final Student s3 = new Student(1002, "Anita", "Female", 25, 2234568793L, 4.2, 'B', true);
  7. System.out.println("student1: " + s1.name);
  8. System.out.println("student2: " + s2.name);
  9. System.out.println("student3: " + s3.name);
  10.  
  11. Student[] students = {s1, s2, s3};
  12.  
  13. // Before Swap
  14. System.out.println("\n\nBefore Swap\n--------");
  15. System.out.println("student1: " + students[0].name);
  16. System.out.println("student2: " + students[1].name);
  17. System.out.println("student3: " + students[2].name);
  18.  
  19.  
  20. swap_s1_n_s3(students, 0, 2);
  21.  
  22. // After swap
  23. System.out.println("\n\nAfter Swap, Inside StudentTest class\n--------");
  24.  
  25. System.out.println("student1: " + students[0].name);
  26. System.out.println("student2: " + students[1].name);
  27. System.out.println("student3: " + students[2].name);
  28.  
  29. }
  30.  
  31.  
  32. static void swap_s1_n_s3(Student[] students, int first, int last) {
  33. System.out.println("\n\n------------\nINSIDE SWAP METHOD");
  34. Student s5;
  35. s5 = students[first];
  36. students[first] = students[last];
  37. students[last] = s5;
  38.  
  39. System.out.println("\n\nstudent1: " + students[0].name);
  40. System.out.println("student2: " + students[1].name);
  41. System.out.println("student3: " + students[2].name);
  42. System.out.println("\nEXIT SWAP METHOD");
  43. }
  44. }
  45.  
  46. class Student {
  47. static int computeCount;
  48. int id;
  49. int age;
  50. String name;
  51. String gender;
  52. short rank;
  53. double gpa;
  54. long phone;
  55. char degree;
  56.  
  57. boolean international;
  58. double tutionfees = 12000;
  59. double internationalFees = 5000;
  60.  
  61. Student(int id, String name, String gender, int age, long phone, double gpa, char degree) {
  62. this(id, name, gender, age, phone, gpa, degree, false);
  63. }
  64.  
  65.  
  66. Student(int id, String name, String gender, int age, long phone, double gpa, char degree, boolean international) {
  67. this.id = id;
  68. this.name = name;
  69. this.gender = gender;
  70. this.age = age;
  71. this.phone = phone;
  72. this.gpa = gpa;
  73. this.degree = degree;
  74. this.international = international;
  75. }
  76. }
Success #stdin #stdout 0.09s 36540KB
stdin
Standard input is empty
stdout
student1: John
student2: Indresh
student3: Anita


Before Swap
--------
student1: John
student2: Indresh
student3: Anita


------------
INSIDE SWAP METHOD


student1: Anita
student2: Indresh
student3: John

EXIT SWAP METHOD


After Swap, Inside StudentTest class
--------
student1: Anita
student2: Indresh
student3: John