
正文
使用Java数组实现双色球选号
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
package com.hm.test; import java.util.Random; /**
* 模拟双色球生成
* *1.从1到16中产生一个篮球的随机数
*2.从1到33中产生出6个红色的球的随机数
* @author hm
*/
public class DoubleBar { public static void main(String[] args) {
int[] a = redBar(); System.out.println("产生的双色球数字是:"); for(int i = 0; i < a.length; i++){
System.out.print(a[i] + " ");
}
System.out.println(blueBar());
} /*产生一个蓝球的随机数*/
public static int blueBar(){
Random random = new Random();
return random.nextInt(16) + 1;
} /*产生6个红球的随机数*/
public static int[] redBar(){
int[] a = new int[6];
Random random = new Random(); /*把产生的数字保存到数组中*/
for(int i = 0; i < 6; i ++){
a[i] = random.nextInt(33) + 1;
}
return a;
} }






