- public static Set<Student> getScore(Comparator<Student> cmp)throws IOException{
- Set<Student> stuSet = null;//盲点:如果写在if里面,下面会出现stuSet变量找不到的错误,因为判断语句可能执行不到。
- if(cmp == null)
- /*Set<Student>*/ stuSet = new TreeSet<Student>();
- else
- stuSet = new TreeSet<Student>(cmp);
- BufferedReader bufIn = new BufferedReader(new InputStreamReader(System.in));
-
- String str = null;
- while((str = bufIn.readLine())!=null){
- if(str.equals("over"))
- break;
- String[] stuInfo = str.split(",");
-
- Student stu = new Student(stuInfo[0],Integer.parseInt(stuInfo[1]),Integer.parseInt(stuInfo[2]),Integer.parseInt(stuInfo[3]));
-
- stuSet.add(stu);
- }
- return stuSet;
- }
复制代码
|
|