A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 403806022 中级黑马   /  2016-4-2 22:31  /  510 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

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());
                }
        }
}

1 个回复

倒序浏览
你确定问题在那一行
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马