标签:length bool tostring 号码 修改 system void lse 基础
import java.util.Arrays;
import java.util.Random;
public class HomeWork02 {
public static void main(String[] atgs){
Random random = new Random();
int[] balls = new int[6];
boolean [] flags =new boolean[33];
for (int i = 0; i < balls.length; i++) {
//设置随机下标(0~32)
int num =random.nextInt(33);
if(flags[num]==false){//如果状态是false表示没选过
balls[i] = num+1;//取数字
flags[num]=true;//修改状态
}else{
i--;//如果状态为true本次循环作废
}
}
System.out.println(Arrays.toString(balls));
//添加一个蓝球
balls = Arrays.copyOf(balls, balls.length+1);
int blue = random.nextInt(16)+1;
balls[balls.length-1]=blue;
System.out.println(Arrays.toString(balls));
}
}
java基础:随机生成一组双色球号码(6个红色号码在前,1个蓝色号码在后) (红球号码范围 1~33,蓝色号码 1~16)(需要去重)
标签:length bool tostring 号码 修改 system void lse 基础
原文地址:https://www.cnblogs.com/C33baby/p/12781263.html