这样做的主要目的是在阵列中循环,看看你是否有中奖号码,但我无法弄清楚如何做到这一点?然后我必须将这个中奖号码与我用它做的赌注相匹配,我也无法弄明白该怎么做。
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);
}
}
答案 0 :(得分:0)
获取一个数字然后检查数组中的数字是否为
int bet = keyboard.nextInt();
for (int number : numbers)
if (number == bet)
// bet found in array