我試圖計算一個玩家玩固定金額的樂透和小丑遊戲可以玩多少回合。在Java中循環中減去一個變量
public static void example() {
int money = 200;
int lottoCost = 4;
int jokerCost = 3;
int costTogether = lottoCost+jokerCost;
int rounds = 0;
for (int i = money; i <= 0; rounds++) {
money = money-costTogether;
}
System.out.println("With " + money + " euros, you can play "
+ rounds + " rounds.");
System.out.println("");
}
該代碼當前打印的文本「200歐元,你可以玩0回合。」 因此,它不會爲輪變量添加+1。我究竟做錯了什麼?
循環從未輸入,這就是爲什麼你看到你所看到的。 – Bala 2014-10-09 10:48:03
嘗試在紙上進行for-loop。 – 2014-10-09 10:49:28
爲什麼使用for循環? – Sambuca 2014-10-09 10:50:26