你是在随机生成双色球的红球啊。。。
//定义String类型的一维数组,01 - 33 即双色球的红球
String[] pool = {"01","02","03","04","05","06","07",
"08","09","10","11","12","13","14","15","16",
"17","18","19","20","21","22","23","24","25",
"26","27","28","29","30","31","32","33"};
//定义一个长度为32的boolean类型的数组,用于判断该随机数是否已经占用
boolean[] used = new boolean[pool.length];
//定义一个随机数生成类
Random random = new Random();
//定义用于最终存储6个红球的String数组
String[] balls = new String[6];
//定义下标
int i=0;
while(true){
//随机获取一个0-32的下标
int index = random.nextInt(pool.length);//[0,33)
//如果这个下标已经被占用了,跳出本次循环
if(used[index]){
continue;
}
//将该下标对应的那个红球的数赋值给上面定义的数组
balls[i++] = pool[index];
//将该红球设置为占用,即已经摇出来了
used[index]=true;
//如果是最后一个球,跳出整个循环
if(i==balls.length){
break;
}
}
//对结果进行排序
Arrays.sort(balls);
balls = Arrays.copyOf(balls, balls.length+1);
balls[balls.length-1]=pool[random.nextInt(16)];
汗 哪有人这么有时间帮你解释呀,你要学会看代码才行,看不懂的帮你解释