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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 张迁 中级黑马   /  2013-5-19 22:52  /  1027 人查看  /  3 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 张迁 于 2013-5-19 23:35 编辑

跟老师的代码对了好几遍,哪里出错了?
比如: 输入:张三,34,45,56
输出的是:张三,34,45,0  为什么第三个值穿不进去啊?
  1. public class Exercise4 {

  2.         public static void main(String[] args) throws IOException {
  3.         
  4.                 Set<Student> set = new TreeSet<>();
  5.                 Scanner sc = new Scanner (System.in);
  6.                 System.out.println("请输入学生成绩:");
  7.                
  8.                 while (sc.hasNextLine()) {
  9.                         String str = sc.nextLine();
  10.                         if ("quit".equals(str)) {
  11.                                 sc = new Scanner( new FileInputStream("student.txt"));
  12.                                 continue;
  13.                         }
  14.                         String[] arr = str.split(",");
  15.                         Student s = new Student(arr[0], Integer.parseInt(arr[1]), Integer.parseInt(arr[2]), Integer.parseInt(arr[3]));
  16.                         set.add(s);                                       
  17.                         
  18.                 }
  19.                
  20.                 BufferedWriter bw = new BufferedWriter(new FileWriter("student.txt"));
  21.                 for (Student student : set) {
  22.                         System.out.println(student);
  23.                         bw.write(student.toString());
  24.                         bw.newLine();
  25.                 }
  26.                 bw.close();
  27.         }
复制代码

评分

参与人数 1技术分 +1 收起 理由
袁梦希 + 1

查看全部评分

3 个回复

倒序浏览
这个问题应该是你的Student类里出了问题, 你应该把Student类代码贴上来一起看看
回复 使用道具 举报
breeze 发表于 2013-5-19 23:25
这个问题应该是你的Student类里出了问题, 你应该把Student类代码贴上来一起看看 ...

哈哈,就是类写错了,可见你肯定仔细看我代码了,十分感谢!
回复 使用道具 举报
哎呀,被抢了,哥哥。要等你的技术分呢
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马