package homework;
import java.util.Arrays;
import java.util.Random;
public class DoubleBoll {
public static void main(String[] args){
System.out.println(create());
}
//一堆东西放一块一般就是数组,
//红球:1~33 取6个 ,不重复,排序
//篮球: 1~16 取1个,
//随机生成一组双色球号码
public static String create(){
String[] redPool = new String[33]; //红球池,对象类型的默认值null
for(int i=0;i<redPool.length;i++){
char[] ch = {'0','0'};
String s = Integer.toString(i+1);//把数字:1转化成字符串: "1"
char[] num = s.toCharArray();//把字符串展转化成字符数组
System.arraycopy(num, 0, ch,
ch.length-num.length, num.length);//数组复制
String ball = new String(ch);
redPool[i] = ball;
}
String[] bluePool = ("01,02,03,04,05,06,07,08,09,"+
"10,11,12,13,14,15,16").split(",");
boolean[] used = new boolean[redPool.length];
Random r = new Random();
String[] allBall = new String[7];
for(int i=0;i<6;i++){
int idx;
do{
idx = r.nextInt(redPool.length);//0~32
}while(used[idx]);//如果使用了,继续找下一个
used[idx] = true;//标记使用
allBall[i] = redPool[idx];//取出一个未使用的红球
}
allBall[allBall.length-1] = "99";//技巧性欺骗
Arrays.sort(allBall);
allBall[allBall.length-1] = bluePool[r.nextInt(bluePool.length)];
return Arrays.toString(allBall);//字符串连成数组
}
}
双色球
最新推荐文章于 2023-05-12 10:46:54 发布