We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
public class DoubleColorsBallDemo { public static void main(String[] args) { generateNum();//调用生成双色球号码的方法 } public static void generateNum(){ int[] redBallPool = new int[33];//1.构建33个红球的数组 boolean[] redBallFlag = new boolean[33];//2.构建红球标志数组 Random rm = new Random(); for(int i=0;i<33;i++){ redBallPool[i] = i+1;//给红球数组中放球,球从1号到33号 } int[] choosenRedBall = new int[6];//3.构建红球的中奖号码数组 int length = 0;//设置一个变量,来标记有几个红球被选中,每次找到一个符合的就加1 while(length != 6){//开始选球 int index = rm.nextInt(33); if(!redBallFlag[index]){//先判断球是否可用,即之前有没有被选中过 redBallFlag[index] = true;//如果可用,先把他标记改一下,代表已经被选中过,不能再被选了 choosenRedBall[length] = redBallPool[index];//存放到选中的数组中 length++;//标记加1 } } int blueBall = rm.nextInt(16)+1;//生成蓝球 //排序,使用Arrays.sort(); Arrays.sort(choosenRedBall);//对红球排序 System.out.println("红球:"+Arrays.toString(choosenRedBall)+",蓝球"+blueBall); }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
The text was updated successfully, but these errors were encountered: