packageredom;importjava.util.Random;publicclassTest_01{publicstaticvoidmain(String[] args){int[] arrInt =newint[5];Random ra =newRandom();//生成1~100以内的随机数for(int i =0; i <arrInt.length ; i++){
arrInt[i]=-1;}//初始数组下标int index =0;//如果指针元素小于数组长度则一直循环while(index < arrInt.length){int num = ra.nextInt(11);//如果数组中不包含这个元素则赋值给数组if(!contains(arrInt,num)){
arrInt[index++]= num;}}//打印for(int k =0; k< arrInt.length;k++){System.out.println(arrInt[k]);}}//传一个数组对象与一个值进行对比publicstaticbooleancontains(int[] arr,int key){for(int i =0; i < arr.length ; i++){//如果相等返回trueif(arr[i]== key){returntrue;}}returnfalse;}}