int [] arr = new int [10];
for(int x = 0 ;x < 10; x++){
int random = new Random().nextInt(100) + 1;//生成0-99 的数 要求是1-100所以+1
arr[x] = random; //将随机数赋值给数组
}
putValueToList(arr);
writeArrToFile(arr);
int [] arr = new int [10];
for(int x = 0 ;x < 10; x++){
int random = new Random().nextInt(100) + 1;//生成0-99 的数 要求是1-100所以+1
arr[x] = random; //将随机数赋值给数组
}
putValueToList(arr);
writeArrToFile(arr);
public static void main(String[] args) throws Exception {
ArrayList<Integer> str =new ArrayList<Integer>();
int[] number=new int[10];
for (int i = 0; i < 10; i++) {
Random random =new Random();
int randomNumber=random.nextInt(100)+1;
number[i]=randomNumber;
if(number[i]>=10){
str.add(number[i]);
}
}
System.out.println(str);
//给定一个不同的key值,将小于10的数字放在Map集合中
HashMap<Integer,Integer> mapping=new HashMap<Integer,Integer>();
int count=0;
for (Integer thisNum : number) {
if(thisNum<10)
mapping.put(count++, thisNum);
}
System.out.println(mapping);
BufferedWriter fw = new BufferedWriter(new FileWriter("number.txt"));
for (int thisnumber: number) {
fw.write(thisnumber+"");
fw.newLine();
}
fw.close();
ArrayList<Integer> list =new ArrayList<Integer>();
for (int i = 0; i < number.length; i++) {
boolean it=list.contains(number[i]);
if(it==false){
list.add(number[i]);