class Ideone {
public static void main
(String args
[]) { final Student s1 = new Student(1000, "John", "Male", 18, 2234567890L, 3.8, 'B');
final Student s2 = new Student(1001, "Indresh", "Male", 20, 2234567893L, 4.0, 'C', true);
final Student s3 = new Student(1002, "Anita", "Female", 25, 2234568793L, 4.2, 'B', true);
System.
out.
println("student1: " + s1.
name); System.
out.
println("student2: " + s2.
name); System.
out.
println("student3: " + s3.
name);
Student[] students = {s1, s2, s3};
// Before Swap
System.
out.
println("\n\nBefore Swap\n--------"); System.
out.
println("student1: " + students
[0].
name); System.
out.
println("student2: " + students
[1].
name); System.
out.
println("student3: " + students
[2].
name);
swap_s1_n_s3(students, 0, 2);
// After swap
System.
out.
println("\n\nAfter Swap, Inside StudentTest class\n--------");
System.
out.
println("student1: " + students
[0].
name); System.
out.
println("student2: " + students
[1].
name); System.
out.
println("student3: " + students
[2].
name);
}
static void swap_s1_n_s3(Student[] students, int first, int last) {
System.
out.
println("\n\n------------\nINSIDE SWAP METHOD"); Student s5;
s5 = students[first];
students[first] = students[last];
students[last] = s5;
System.
out.
println("\n\nstudent1: " + students
[0].
name); System.
out.
println("student2: " + students
[1].
name); System.
out.
println("student3: " + students
[2].
name); System.
out.
println("\nEXIT SWAP METHOD"); }
}
class Student {
static int computeCount;
int id;
int age;
short rank;
double gpa;
long phone;
char degree;
boolean international;
double tutionfees = 12000;
double internationalFees = 5000;
Student
(int id,
String name,
String gender,
int age,
long phone,
double gpa,
char degree
) { this(id, name, gender, age, phone, gpa, degree, false);
}
Student
(int id,
String name,
String gender,
int age,
long phone,
double gpa,
char degree,
boolean international
) { this.id = id;
this.name = name;
this.gender = gender;
this.age = age;
this.phone = phone;
this.gpa = gpa;
this.degree = degree;
this.international = international;
}
}
Y2xhc3MgSWRlb25lIHsKCiAgICBwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmcgYXJnc1tdKSB7CiAgICAgICAgZmluYWwgU3R1ZGVudCBzMSA9IG5ldyBTdHVkZW50KDEwMDAsICJKb2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