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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 走遍世界找寻你 中级黑马   /  2013-11-20 23:08  /  1248 人查看  /  3 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

import itcast.cm.bean.Student;

import java.util.Comparator;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;


public class Demo6 {
        public static void main(String[] args) {
                Set<Student> set = new TreeSet<>(new Comparator<Student>() {
                        public int compare(Student s1, Student s2){
                                int num = s1.getSum()- s2.getSum();
                                return num == 0 ? 1 : num;
                        }
                });
                Scanner sc = new Scanner(System.in);
                System.out.println("请输入信息:");
                while(true) {
                        String line = sc.nextLine();
                        if("quit".equals(line));
                                break;
                        String[] arr = line.split(",");
                        set.add(new Student(arr[0], Integer.parseInt(arr[1]), Integer.parseInt(arr[2]),
                                        Integer.parseInt(arr[3])));
                }
                System.out.println("请输入学生信息:");
                for (Student student : set) {
                        System.out.println(student);
                }
        }
}
第23行有什么错误?为什么eclipse也没有提示.

评分

参与人数 1技术分 +1 收起 理由
滔哥 + 1

查看全部评分

3 个回复

倒序浏览
给出错误提示啊?没有提示怎么知道什么错误
回复 使用道具 举报
   if("quit".equals(line));
                                break;
                        String[] arr = line.split(",");
当我删除其他所有代码时候
我发现你的if()后面有个;
这样break;100/100会运行
break;后面不能加代码的,因为肯定运行不到。所以报错
去掉if()后面的;就可以了

评分

参与人数 1技术分 +1 收起 理由
滔哥 + 1

查看全部评分

回复 使用道具 举报
break直接跳出循环了,循环里后边代码不会执行。把break后面的代码加到break前面应该就可以执行了
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马