-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPractice.java
More file actions
36 lines (33 loc) · 983 Bytes
/
Practice.java
File metadata and controls
36 lines (33 loc) · 983 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
public class Practice implements Comparable<Practice> {
private int a, b;
public Practice(int a, int b) {
this.a = a;
this.b = b;
}
public int compareTo(Practice other)
{
if(this.a>other.a){
return 1;
} else if (this.a<other.a){
return -1;
} else if(this.b>other.b){
return 1;
} else if (this.b<other.b){
return -1;
} else{
return 0;
}
}
public static void main(String[] args) {
Practice p1 = new Practice(2,3);
Practice p2 = new Practice(4,1);
Practice p3 = new Practice(2,3);
Practice p4 = new Practice(2,4);
Practice p5 = new Practice(2,1);
System.out.println(p1.compareTo(p2));
System.out.println(p1.compareTo(p3));
System.out.println(p2.compareTo(p3));
System.out.println(p1.compareTo(p4));
System.out.println(p1.compareTo(p5));
}
}