導航:首頁 > 編程語言 > java隨機抽取

java隨機抽取

發布時間:2023-07-11 01:51:48

A. 請問用java從1-33個整數中隨機抽取6個數字 且不重復 1-16隨機抽取一個數,給小球

完整代碼為:

public class Main {

public static void main(String[] args) {
int index = 1;
int[] redBalls = new int[6];

Random random = new Random();
boolean getMoreRed = true;
boolean getAgain;
System.out.println("開始抽取紅球!");
while (getMoreRed) {
getAgain = false;
int red = random.nextInt(36) + 1;
System.out.print("本次抽取到的紅球為:[" + red + "]!");
for (int i = 0; i < index; i++) {
if (redBalls[i] == red) {
System.out.print("重復抽取,將重新抽取紅球");
getAgain = true;
break;
}
}
System.out.println("");
if (getAgain){
continue;
}
redBalls[index - 1] = red;
index++;
getMoreRed = index < 7;
}
System.out.println("抽取到的紅球為:");
Arrays.sort(redBalls);
for (int redBall : redBalls) {
System.out.print(redBall + " ");
}

System.out.println(" 開始抽取藍球!");
System.out.println("本次抽取到的藍球為:[" + (random.nextInt(16) + 1) + "]!");
}
}

閱讀全文

與java隨機抽取相關的資料

熱點內容
哪裡找到轉轉app 瀏覽:577
蘋果二次app怎麼注冊 瀏覽:584
國際服體驗服伺服器為什麼爆滿 瀏覽:111
微信商城模板源碼 瀏覽:433
網頁的源碼怎麼讀取 瀏覽:399
ubuntu命令打開軟體 瀏覽:760
如何實現對講頻道加密 瀏覽:348
福州8000的程序員去深圳多少 瀏覽:641
保存加密是什麼意思 瀏覽:40
安裝不了軟體顯示加密目錄 瀏覽:908
php53下載64位 瀏覽:96
osip源碼結構 瀏覽:954
如何刪除加密網站 瀏覽:714
亞太碳交易app怎麼用 瀏覽:955
怎麼推銷程序員 瀏覽:498
程序員再就業求助 瀏覽:106
知網程序員如何做產品 瀏覽:531
圖片怎麼樣用文件夾發送 瀏覽:32
qq獲取qq頭像軟體源碼 瀏覽:548
視頻怎麼加密保護 瀏覽:72