當前位置:商標查詢大全網 - 彩票開獎 - 求java高手求助! 老師留的結業題 用java編譯道關於雙色球的代碼 要求:(紅球33選1)選完

求java高手求助! 老師留的結業題 用java編譯道關於雙色球的代碼 要求:(紅球33選1)選完

雙色球紅球是33選6,下面是電腦機選代碼:

/**

* 實現生成 雙色球彩票號碼 算法

*

* 實現方法 返回彩票號碼 如:[03, 06, 08, 12, 15, 23, 28]

*

* 1) 生成紅球號碼

* 數據 紅球 :"01" ~ "33"

* 使用標記: f, f, ...

* 紅球號 : { ^, ^, ^, ^, ^, ^}

* index = 0 生成號碼的個數

* 2) 生成藍色球號碼

*/

public class Demo10 {

public static void main(String[] args) {

String[] balls = gen();

System.out.println(Arrays.toString(balls));

}

public static String[] gen(){

String[] pool = {"01","02","03","04","05","06","07",

"08","09","10","11","12","13","14","15","16",

"17","18","19","20","21","22","23","24","25",

"26","27","28","29","30","31","32","33"};

boolean[] used = new boolean[pool.length];

String[] balls = new String[6];

int index = 0;

Random r = new Random();

do{

int i = r.nextInt(pool.length);

if(used[i]){ continue; }

balls[index++] = pool[i];

used[i] = true;

}while(index!=balls.length);

Arrays.sort(balls);

//擴容,追加藍色球號碼

balls = Arrays.copyOf(balls, balls.length+1);

balls[balls.length-1] = pool[r.nextInt(16)];

return balls;

}

}