编程语言
首页 > 编程语言> > Java课后题第十二章:12.15(读/写数据)

Java课后题第十二章:12.15(读/写数据)

作者:互联网

示例

public class Test1 {
    public static void main(String[] args) throws IOException {
        File file = new File("InputAndOutput.txt");
        PrintWriter output = new PrintWriter(file);
        Random seed = new Random();
        for (int i = 0; i < 100; i++) {
            int a = seed.nextInt(100);
            output.print(a + " ");
        }
        output.close();

        Scanner input = new Scanner(file);
        Integer[] list = new Integer[100];
        int i = 0;
        while (input.hasNext()) {
            String str = input.next();
            list[i] = Integer.parseInt(str);
            i++;
        }
        input.close();

        Arrays.sort(list);
        for (i = 0; i < 100; i++) {
            System.out.println(list[i]);
        }
    }
}

标签:Java,file,int,list,12.15,课后,input,new,100
来源: https://blog.csdn.net/liudada01/article/details/121445918