java生成不重复的随机数组
public class Laji {
public static void main(String[] args) {
int[] red=new int[6];
int blue=1+random.nextInt(16);
for (int i = 0; i <red.length ; i++) {
red[i]=1+random.nextInt(33);
for (int j=0;j<i;j++){
while (red[i]==red[j]){
i--;
}
}
}
for(int a:red){
System.out.print("红球有:"+a+" ");
}
System.out.println();
System.out.println("蓝色球:"+blue+" ");
int[] both=new int[red.length+1];
for(int i=0;i<red.length;i++){
both[i]=red[i];
}
int a=both.length - 1;
both[a]=blue;
System.out.print("最终数组:");
for(int b:both){
System.out.print(b+" ");
}
}
}