package com.heima.luntan;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Random;
public class Test2 {
/**
*
随机生成100个1-100的随机int数,存入集合,打印进控制台,
再把这一百个数输入至d:\\java.txt。文件中要显示数字。
* @throws IOException
*/
public static void main(String[] args) throws IOException {
Random r = new Random();
ArrayList<String> list = new ArrayList<>();
while(list.size() < 100) {
list.add(r.nextInt(100) + 1 + "");
}
System.out.println(list);
BufferedWriter bw = new BufferedWriter(new FileWriter("d:\\java.txt"));
for (String string : list) {
bw.write(string);
bw.newLine();
}
bw.close();
}
}
|