public class Deom09_TreeSet {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("请您输入数据,格式是:姓名,语文,数学,英语");
TreeSet<Student> ts = new TreeSet<>(new Comparator<Student>() {
@Override
public int Compare(Student s1, Student s2) { //这一行哪里有问题
int num = s2.getSum() - s1.getSum();
return num == 0 ? 1 : num;
}
});
while(ts.size() < 5){
String line = scan.nextLine();
String[] str = line.split(",");
int chinese = Integer.parseInt(str[1]);
int math = Integer.parseInt(str[2]);
int english = Integer.parseInt(str[3]);
ts.add(new Student(str[0],chinese,math,english));
}
System.out.println("排列后的学生信息");
for (Student s : ts) {
System.out.println(s.toString());
}
}
}
|
|