//获取10个1至20的随机数,要求随机数不能重复。
public class Test {
public static void main(String[] args) {
Random ran = new Random();
int[] arr = new int[10];
for (int i = 0; i < arr.length; i++) {
int num = ran.nextInt(20)+1;
if(!luckNum(arr,num)){
arr[i] =num;
}else{
i--;
}
}
System.out.println(Arrays.toString(arr));;
}
public static boolean luckNum(int[]arr,int lucknum ){
boolean flag = false;
for (int i = 0; i < arr.length; i++) {
if(arr[i]==lucknum){
flag =true;
}
}
return flag;
}
}