简体   繁体   English

如何将数字匹配到两个不同的数组

[英]How to match a number to two different arrays

The main goal of this is to cycle through the array and see if you have the winning number but I can't figure out how to do it? 这样做的主要目的是遍历整个数组,看看您是否有中奖号码,但我不知道该怎么做? Then I have to match that winning number to the bet I made with it which I also can't figure out how to do. 然后,我必须将该获胜号码与我用它进行的下注匹配,但我也想不出该怎么做。

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);
    }
}

Get a number then check if the number in the array: 获取一个数字,然后检查数组中的数字:

int bet = keyboard.nextInt();

for (int number : numbers)
    if (number == bet)
        // bet found in array

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM