Import java.util.*;
Import java.io.*;
public class main{
static int [] DP = new int [1010];
public static void Main (String [] args) throws ioexception{
Mouse [] mice = new Mouse [1010];
FileReader fr=new FileReader ("In.txt"); Read file
BufferedReader read = new BufferedReader (FR);
String str = "";
int n=1;
while ((str = read.readline ())!=null) {
String [] s= str.split ("");
Mice[n] = new Mouse ();//Object instantiation, very important
Mice[n].weight = Integer.parseint (S[0]);
Mice[n].speed =integer.parseint (s[1]);
n++;
}
SYSTEM.OUT.PRINTLN (n);
Arrays.sort (Mice,1,n);//sort (int start,int end) includes the start index, not including the end index
for (int i=1;i<n;i++) {
System.out.println (mice[i].weight+ "" +mice[i].speed);
}
}
}
Class Mouse implements comparable{//Implement comparable interface
int weight;
int speed;
public int compareTo (Object o) {//Override CompareTo method
Mouse m= (Mouse) o;
Return weight>m.weight?1: (weight==m.weight?0:-1);
}
}
Sorting Java object Arrays