gpt4 book ai didi

java - 我正在比较来自 2 个独立数组的 2 组整数值

转载 作者:行者123 更新时间:2023-12-01 14:13:09 25 4
gpt4 key购买 nike

任何人都可以帮忙吗?我正在比较 2 组彩票号码,其中 userNumbers 是您的彩票中的号码,而数字数组代表网站上彩票抽奖的号码。当我运行该程序并输入 6 个正确的数字时,该程序会通知我我赢得了大奖。但是,如果匹配的数字少于 6 个,我就会陷入 while 循环。任何人都可以帮助我摆脱这个困境,这样如果我匹配 2 个数字,程序会通知我我匹配了 2 个数字,如果我匹配 3 个数字,它会通知我这个等等!如果我匹配奖金,程序将通知我我已匹配奖金和 (n) 个号码。我对 Java 很陌生,并且已经考虑这个问题有一段时间了!提前致谢!

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;
boolean jackpot;

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 <SIZE; loop++ )
{
for (int loopOther = 0; loopOther < numbers.length; loopOther++)
{
if (userNumbers[loop] == numbers[loopOther])
{
lottCount++;
} else if (userNumbers[loop] == bonusBall)
{
bonus = true;
}
}//for

}//forMain

if (lottCount == 6)
{
jackpot = true;
System.out.println("You have matched all numbers!! Congratulations you are a jackpot winner");
}else System.out.println(" You have matched " + lottCount + " numbers. Please visit the webpage did you see what you have won");
while (lottCount < 6)

if (bonus)
{
System.out.println("You have matched " + lottCount + " numbers " + "and" + " the bonus ball"
+ bonusBall + " Please see the website to check your prize.");
} else
System.out.println("You have not won at this time. ");

最佳答案

看起来“while (lottCount < 6)”是不必要的,把它去掉,它应该可以工作,看起来你想要一些类似的东西:

if (lottCount == 6) {
System.out.println("You have matched all numbers!! Congratulations you are a jackpot winner");
}
else if (!bonus) {
System.out.println(" You have matched " + lottCount + " numbers. Please visit the webpage did you see what you have won");
}

if (bonus) {
System.out.println("You have matched " + lottCount + " numbers " + "and" + " the bonus ball"
+ bonusBall + " Please see the website to check your prize.");
}

关于java - 我正在比较来自 2 个独立数组的 2 组整数值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18332825/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com