标签:
1 package hello; 2 3 import java.util.Comparator; 4 import java.util.HashSet; 5 import java.util.Random; 6 import java.util.Scanner; 7 import java.util.TreeSet; 8 9 public class Test02 { 10 11 public static void main(String[] args) { 12 TreeSet<Student> ts=new TreeSet<Student>(new Comparator<Student>() { 13 14 @Override 15 public int compare(Student o1, Student o2) { 16 // TODO Auto-generated method stub 17 int num=o1.getSum()-o2.getSum(); 18 int num2=num==0?o1.getChinese()-o2.getChinese():num; 19 int num3=num2==0?o1.getMath()-o2.getMath():num2; 20 int num4=num3==0?o1.getEnglish()-o2.getEnglish():num3; 21 return num4; 22 } 23 24 }); 25 26 for(int x=1;x<=5;x++){ 27 Scanner sc=new Scanner(System.in); 28 System.out.println("请输入第:"+x+"学生的名称"); 29 String name=sc.nextLine(); 30 System.out.println("请输入语文成绩:"); 31 String chineseString=sc.nextLine(); 32 33 System.out.println("请输入数学成绩:"); 34 String mathString=sc.nextLine(); 35 36 System.out.println("请输入英语成绩:"); 37 String englishString=sc.nextLine(); 38 39 Student s=new Student(); 40 s.setName(name); 41 s.setChinese(Integer.parseInt(chineseString)); 42 s.setMath(Integer.parseInt(mathString)); 43 s.setEnglish(Integer.parseInt(englishString)); 44 45 ts.add(s); 46 } 47 System.out.println("录入完毕"); 48 for(Student s:ts){ 49 System.out.println(s.getName()+"\t"+s.getChinese()+"\t"+s.getMath()+"\t"+s.getEnglish()); 50 } 51 } 52 }
标签:
原文地址:http://www.cnblogs.com/chengling/p/4774763.html