Scanner sc = new Scanner(System.in);
System.out.println("请输入5个学生成绩格式是:(姓名,语文成绩,数学成绩,英语成绩)");
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 = sc.nextLine();
try {
String[] arr = line.split(",");
int chinese = Integer.parseInt(arr[1]);
int math = Integer.parseInt(arr[2]);
int english = Integer.parseInt(arr[3]);
ts.add(new Student(arr[0], chinese, math, english));
} catch (Exception e) {
System.out.println("录入格式有误,输入5个学生成绩格式是:(姓名,语文成绩,数学成绩,英语成绩");
}
}
System.out.println("排序后的学生成绩是:");
for (Student s : ts) {
System.out.println(s);
}aa");
list.add("bbb");
list.add("ddd");
list.add("ddd");
sort(list);
System.out.println(list);
Scanner sc =new Scaner(System.in);
System.out.println("请输入一行字符串:");
String line=sc.nextList();
char[]arr=line.toCharArray();
TreeSet<Character> ts =new TreeSet<>(new Comparator<Character>())
System.out.println(s);
|
|