Java 我正在比较两个独立数组中的两组整数,以匹配彩票号码

Java 我正在比较两个独立数组中的两组整数,以匹配彩票号码,java,arrays,Java,Arrays,我有一个问题,我的循环,我意识到有可能是一个轻微的调整,需要作出正确的工作方式,但我只是不明白这是什么!我已包括以下代码: final int SIZE = 6; //array to store user numbers int [] userNumbers = new int[SIZE]; boolean found = false; int pos = 0; boolean bonus = false

我有一个问题,我的循环,我意识到有可能是一个轻微的调整,需要作出正确的工作方式,但我只是不明白这是什么!我已包括以下代码:

final int SIZE = 6;
         //array to store user numbers
         int [] userNumbers = new int[SIZE];
         boolean found = false;
         int pos = 0;
         boolean bonus = false;
         int lottCount = 0;

         while (pos<SIZE)
         {
            System.out.println("enter your numbers");
            userNumbers[pos]=keyboard.nextInt();
            pos++;
         }
         for (int count: userNumbers)
         {
            System.out.println(count);
         }

         for (int loop = 0; loop <numbers.length; loop++ )
         {
            for (int loopOther = 0; loopOther < SIZE; loopOther++)
            {
               if (userNumbers[loop] == numbers[loopOther])
                  lottCount++;
            }
               if (userNumbers[loop] == bonusBall)
               {
                  bonus = true;
                  System.out.println("You have matched " + lottCount + " numbers " + "and" + " the bonus ball" + bonusBall);
               }
               else 
                  {
                  System.out.println("You have not won at this time");
                  }
         }

         System.out.println("You have matched " + lottCount + " numbers");

我只想让程序将每种情况通知我一次。有人能帮我吗?提前谢谢

你的问题是什么?
     for (int loop = 0; loop <numbers.length; loop++ )
     {
        for (int loopOther = 0; loopOther < SIZE; loopOther++)
        {
           if (userNumbers[loop] == numbers[loopOther])
              lottCount++;
        }
        if (userNumbers[loop] == bonusBall)
        {
           bonus = true;
        }
     }
     if (bonus)
     {
         System.out.println("You have matched " + lottCount + " numbers " + "and" + " the bonus ball" + bonusBall);
     }
     else 
     {
         System.out.println("You have not won at this time");
     }
     for (int loop = 0; loop <numbers.length; loop++ )
     {
        for (int loopOther = 0; loopOther < SIZE; loopOther++)
        {
           if (userNumbers[loop] == numbers[loopOther])
              lottCount++;
        }
        if (userNumbers[loop] == bonusBall)
        {
           bonus = true;
        }
     }
     if (bonus)
     {
         System.out.println("You have matched " + lottCount + " numbers " + "and" + " the bonus ball" + bonusBall);
     }
     else 
     {
         System.out.println("You have not won at this time");
     }
     for (int number : numbers)
     {
        for (int userNumber : userNumbers)
        {
           if (userNumber == number)
              lottCount++;
        }
        if (userNumber == bonusBall)
        {
           bonus = true;
        }
     }
     if (bonus)
     {
         System.out.println("You have matched " + lottCount + " numbers " + "and" + " the bonus ball" + bonusBall);
     }
     else 
     {
         System.out.println("You have not won at this time");
     }