0
這樣做的主要目標是循環訪問數組,看看您是否有獲勝的號碼,但我無法弄清楚如何做到這一點?然後,我必須將這個中獎號碼與我所做的下注匹配起來,我也無法知道該怎麼做。如何將一個數字與兩個不同的數組進行匹配
public class FinalRoulette {
public static void main(String[] args) {
int number[];
number = new int[37];
int bet[];
bet = new int[37];
int numbers = 1;
double x = 38, totalwager = 0, money = 0;
Scanner keyboard = new Scanner(System.in);
for (int i = 0; i <= x; i++)
while (numbers > 0) {
System.out.print("What number do you want to bet on-"
+ "enter 0 to stop betting: ");
numbers = keyboard.nextInt();
number[i] = numbers;
System.out.printf("How much do you want to bet?: ");
bet[i]=keyboard.nextInt();
totalwager += bet[i];
}
int randomnum = 0;
Random randomNumbers = new Random();
randomnum = randomNumbers.nextInt(37);
System.out.println("The winning number was " + randomnum);
}
}
看起來像一個家庭作業。首先建議與變量名稱一致。容易混淆數字和數字,特別是當數字只有一個數字時,但數字是一組數字。也許電話號碼betNumber。 – Meier