public static void main(String[] args) throws IOException {
TreeSet<Outer> ts = new TreeSet<Outer>(new Comparator<Outer>() {
@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();
}
将学生成绩从集合存储至文件
最新推荐文章于 2022-04-23 23:49:00 发布