Created
January 11, 2020 07:30
-
-
Save scmmishra/9d9cfeaea258a443f6cf2aa46b5d49b2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
import java.util.*; | |
class Marksheet { | |
int roll_no, total; | |
String name; | |
public void set_roll(int roll_number) { | |
roll_no = roll_number; | |
} | |
public void set_total(int tot) { | |
total = tot; | |
} | |
public void display() { | |
System.out.println(roll_no + "\t" + total); | |
} | |
public static void main(String[] args) { | |
Marksheet m[] = new Marksheet[6]; | |
m[0] = new Marksheet(); | |
m[0].set_roll(1); | |
m[0].set_total(10); | |
m[1] = new Marksheet(); | |
m[1].set_roll(2); | |
m[1].set_total(20); | |
m[2] = new Marksheet(); | |
m[2].set_roll(3); | |
m[2].set_total(15); | |
m[3] = new Marksheet(); | |
m[3].set_roll(4); | |
m[3].set_total(18); | |
m[0].display(); | |
m[1].display(); | |
m[2].display(); | |
m[3].display(); | |
Arrays.sort(m, new Comparator<Marksheet>() { | |
@Override | |
public int compare(Marksheet m1, Marksheet m2) { | |
return -1; | |
} | |
}); | |
m[0].display(); | |
m[1].display(); | |
m[2].display(); | |
m[3].display(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment