/*
* 2.产生10个1-100的随机数,并放到一个数组中(要求随机数不能重复)
(3)把数组中的数字放到当前文件夹的number.txt文件中
*/
public class Second_Random {
public static void main(String[] args) throws IOException {
FileOutputStream fos = new FileOutputStream("number_random.txt");
Random radom = new Random();
int[] arr = new int[100];
for (int i = 0; i < arr.length;i++) {
int r = radom.nextInt(100);
// if(arr[i]!=(r+1))
arr[i] = r + 1;
fos.write((arr[i]+" ").getBytes());
}
System.out.println("Done!");
fos.close();
}
}
|
|