Skip to content
New issue

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

java数组实现双色球 #168

Open
jeffsui opened this issue Mar 10, 2022 · 0 comments
Open

java数组实现双色球 #168

jeffsui opened this issue Mar 10, 2022 · 0 comments
Labels
Java java

Comments

@jeffsui
Copy link
Owner

jeffsui commented Mar 10, 2022

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);
	}
@jeffsui jeffsui added the Java java label Mar 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Java java
Projects
None yet
Development

No branches or pull requests

1 participant