- import java.io.BufferedWriter;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.util.Scanner;
- import java.util.TreeSet;
- public class BigTestDemo2 {
- public static void main(String[] args) throws IOException {
- TreeSet<Teacher> ts = new TreeSet<Teacher>();
-
- for(int i = 0;i <3;i++){
- Scanner sc = new Scanner(System.in);
- String name = sc.nextLine();
- int age = sc.nextInt();
-
- Teacher t = new Teacher(name,age);
- ts.add(t);
- }
- BufferedWriter bw = new BufferedWriter(new FileWriter("老师.txt"));
- bw.write("姓名"+"\t"+"年龄");
- bw.newLine();
- for(Teacher t : ts){
- String name = t.getName();
- int age = t.getAge();
-
- bw.write(name+"\t"+age);
- bw.newLine();
- bw.flush();
- }
- bw.close();
- }
- }
复制代码 |
|