導航:首頁 > 編程語言 > 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隨機抽取相關的資料

熱點內容
資料庫查詢系統源碼 瀏覽:618
php5314 瀏覽:359
完美國際安裝到哪個文件夾 瀏覽:671
什麼app可以掃一掃做題 瀏覽:541
程序員編碼論壇 瀏覽:927
淘點是什麼app 瀏覽:662
中國高等植物pdf 瀏覽:455
51單片機時間 瀏覽:185
後台如何獲取伺服器ip 瀏覽:269
單片機流水燈程序c語言 瀏覽:237
程序員第二職業掙錢 瀏覽:242
運行里怎麼輸入伺服器路徑 瀏覽:844
pythonstepwise 瀏覽:513
劉一男詞彙速記指南pdf 瀏覽:67
php認證級別 瀏覽:372
方舟編譯啥時候推送 瀏覽:1013
php手機驗證碼生成 瀏覽:678
哲學思維pdf 瀏覽:19
凌達壓縮機有限公司招聘 瀏覽:537
weblogic命令部署 瀏覽:40