test1
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.Comparator;
import java.util.Scanner;
import java.util.TreeSet;
public class IOTest1 {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
TreeSet<Student2> set1 = new TreeSet<>(new Comparator<Student2>() {
@Override
public int compare(Student2 o1, Student2 o2) {
int i1 = o2.getSumScore() - o1.getSumScore();
int i2 = (i1 == 0) ? o2.getChinese() - o1.getChinese() : i1;
int i3 = (i2 == 0) ? o2.getMath() - o1.getMath() : i2;
return (i3 == 0) ? o2.getName().compareTo(o1.getName()) : i3;
}
});
for (int i = 1; i <= 5; i++) {
System.out.println("请输入第 " + i + " 个学生的信息");
System.out.print("请输入姓名: ");
String name = sc.next();
System.out.print("请输入该学生的语文成绩: ");
int chinese = sc.nextInt();
System.out.print("请输入该学生的数学成绩: ");
int math = sc.nextInt();
System.out.print("请输入该学生的英语成绩: ");
int english = sc.nextInt();
set1.add(new Student2(name, chinese, math, english));
}
System.out.println("学生信息录入完毕!!");
BufferedWriter bw = new BufferedWriter(new FileWriter("java/src/com/shujia/day16/studentInfo.txt"));
bw.write("姓名\t\t语文成绩\t\t数学成绩\t\t英语成绩\t\t总分");
bw.newLine();
for (Student2 student2 : set1) {
bw.write(student2.getName() + "\t\t" +
student2.getChinese() + "\t\t" +
student2.getMath() + "\t\t" +
student2.getEnglish() + "\t\t" +
student2.getSumScore());
bw.newLine();
bw.flush();
}
bw.close();
}
}
test2
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.Arrays;
public class IOTest2 {
public static void main(String[] args) throws Exception{
String s = "hcexfgijkamdnoqrzstuvwybpl";
char[] chars = s.toCharArray();
Arrays.sort(chars);
BufferedWriter bw = new BufferedWriter(new FileWriter("java/src/com/shujia/day16/ss.txt"));
bw.write(chars);
bw.flush();
bw.close();
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?