public static void main(String[] args) throws IOException { TreeSetts = new TreeSet (new Comparator () { @Override public int compare(Outer o1, Outer o2) { int num = o1.getSum() - o2.getSum(); return num; } }); BufferedWriter bw = new BufferedWriter(new FileWriter("fos")); Scanner sc = new Scanner(System.in); System.out.println("请输入要输入学生人数"); int num = sc.nextInt(); sc.nextLine(); for (int i = 0; i < num; i++) { System.out.println("学生姓名"); String name = sc.nextLine(); System.out.println("数学成绩"); int math = sc.nextInt(); sc.nextLine(); System.out.println("语文成绩"); int chinese = sc.nextInt(); sc.nextLine(); Outer o = new Outer(name, math, chinese); ts.add(o); } StringBuilder sb = new StringBuilder(); for (Outer o : ts) { sb.append(o.getName()).append(",").append(o.getMath()).append(",").append(o.getChinese()); bw.write(sb.toString()); bw.newline(); bw.flush(); } System.out.println(sb.toString()); bw.close(); }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)