這是Herr Deng桑的教學blog,主要處理作業與班導事務,另外還有數位小品。
package sorting;import java.util.Arrays;import java.util.Comparator;class studentCA implements Comparator<Student>{ public int compare(Student X1, Student X2){ return X1.A-X2.A; }}public class StudentSort { public static void main(String[] args) { Student X[]=new Student[3]; X[0]=new Student(0,"Mary",90 ,85); X[1]=new Student(1,"John",59 ,65); X[2]=new Student(2,"Joe",77 ,75); for(int i=0; i<X.length; i++) X[i].print(); studentCA CA=new studentCA(); Arrays.sort(X,CA); System.out.println("============="); for(int i=0; i<X.length; i++) X[i].print(); }}
張貼留言
1 則留言:
package sorting;
import java.util.Arrays;
import java.util.Comparator;
class studentCA implements Comparator<Student>{
public int compare(Student X1, Student X2){
return X1.A-X2.A;
}
}
public class StudentSort {
public static void main(String[] args) {
Student X[]=new Student[3];
X[0]=new Student(0,"Mary",90 ,85);
X[1]=new Student(1,"John",59 ,65);
X[2]=new Student(2,"Joe",77 ,75);
for(int i=0; i<X.length; i++)
X[i].print();
studentCA CA=new studentCA();
Arrays.sort(X,CA);
System.out.println("=============");
for(int i=0; i<X.length; i++)
X[i].print();
}
}
張貼留言