import java.util.Random;
public class diceSimulation {
private static Random rollDice = new Random();
public static void main(String[] args) {
final int ROLLCOUNT = 100000;
final int SIDES = 12;
int count, dice1, dice2;
int [] doubleCounts = new int [SIDES];
welcome();
for (count=1; count<=ROLLCOUNT;count++){
dice1=roll(SIDES);
dice2=roll(SIDES);
if (dice1==dice2){
doubleCounts[dice1-1]++;
}
}
// Display results totals of paired rolls
for (int idx=0; idx<doubleCounts.length; idx++){
System.out.format(" You rolled set of %d %d times\n",(idx+1), doubleCounts[idx]);
}
}
private static int roll(int sides){
return rollDice.nextInt(sides) + 1;
}
public static void welcome() {
System.out.println("Here are your rolling dice percentages");
}
}
希望這是我的地方,我應該檢查多少次擲骰的每側使用12個邊,而對一些骰子的模擬項目代碼原因我的代碼輸出只給了我數以百計,不加起來是10,000的數字,這是rollount。有人能爲我解決這個問題嗎?我很抱歉,如果我的代碼是壞的,但我是新的編碼和堆棧溢出,所以請讓我知道,如果有什麼我可以修復。爲什麼我的輸出進來數百當我在數千
按照慣例,程序員使用'for(count = 0; count
awiebe
感謝它現在更好的工作,但仍然沒有加起來10000 – JohnYohana
你能給我們一個樣本輸出和你想要的樣本嗎? –