我想要讓這個硬幣折騰程序爲Java工作。我還是很新的,我很確定我搞砸了一堆。任何人都可以看看嗎?無法弄清楚如何讓我的開關保持循環,直到用戶輸入0來停止硬幣翻轉:枚舉硬幣折扣程序卡住
主要目標是詢問用戶有多少翻轉和出多少頭和尾翻轉。然後詢問他們是否想繼續翻轉並將這些翻轉添加到已經完成的翻轉中,並且我必須使用ENUM來完成翻轉。 。 。
import java.util.Random;
import java.util.Scanner;
public class CoinTossing {
private enum Coin { HEADS, TAILS };
private static final Random randomNumbers = new Random();
private static final int HEADS = 1;
private static final int TAILS = 2;
public static void main(String[] args)
{
Scanner input = new Scanner (System.in);
int quantity = 0;
int headSide = 0;
int tailsSide = 0;
System.out.println("How many times would you like to flip the coin? Enter 0 to end.");
int flipNumber = input.nextInt();
while (flipNumber != 0)
quantity = quantity + flipNumber;
for(int x=1; x<=quantity; ++x);
switch (Flip(null))
{
case HEADS:
headSide++;
break;
case TAILS:
tailsSide++;
break;
}
if (flipNumber == 0)
System.out.println("Your Number of flips is" + HEADS +TAILS);
}
private static int Flip(Random randomNumber) {
int toss;
toss = 1+ randomNumber.nextInt(2);
return toss;
}
}
Java不是python,縮進在這裏只用於可讀性目的,它不影響範圍。 – Pshemo
又是什麼'''在這裏做:'for(int x = 1; x <= quantity; ++ x);'? – Pshemo