- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObjectSort.java
More file actions
Latest commit
39 lines (32 loc) · 835 Bytes
/
Copy pathObjectSort.java
File metadata and controls
39 lines (32 loc) · 835 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
importjavax.print.DocFlavor;
importjava.util.*;
publicclassObjectSort {
publicstaticvoidmain(String[] args) {
Student [] arr = newStudent[4];
arr[0] = newStudent("aa",80);
arr[1] = newStudent("bb",90);
arr[2] = newStudent("cc",60);
arr[3] = newStudent("dd",85);
Arrays.sort(arr);
for (Students : arr){
System.out.println(s.name);
}
}
}
classStudentimplementsComparable<Student> {
Stringname;
intmarks;
publicStudent(Stringname, intmarks) {
this.name = name;
this.marks = marks;
}
@Override
publicintcompareTo(Studento) {
if (this.marks > o.marks){
return1;
} elseif (this.marks < o.marks) {
return -1;
}
return0;
}
}