当我尝试运行该程序时,它会询问我的输入,然后只是说“运行”而没有任何输出,直到我关闭它。我没有看到代码有任何问题,我之前在另一台计算机上运行过这个确切的程序(我的家用计算机在处理它的PC上的处理能力远远优于它)这是一个Netbeans错误吗?
int ticket [] = new int [6];
for (int i = 0; i < 6; i++)
{
ticket [i] = Integer.parseInt(JOptionPane.showInputDialog("Input a number:"));
}
int balls[] = new int [7];
for (int i = 0; i < balls.length; i++)
{
boolean keepLooking = true;
int b = (int)(Math.random()*6 + 1);
while(keepLooking)
{
keepLooking = false;
for (int j = 0; j < balls.length; j++)
{
if (balls [j] == b)
{
keepLooking = true;
}
}
}
balls [i] = b;
}
int bonus = balls[6];
int matching = 0;
boolean bonusMatch = false;
for (int i = 0; i < 6; i++)
{
for (int j = 0; j < 7; j++)
{
if (ticket[i] == balls[j])
{
matching = matching +1;
}
}
if (ticket[i] == balls[6])
{
bonusMatch = true;
}
}
System.out.println("The winning balls are: ");
for (int i = 0; i < 6; i++)
{
System.out.print(" " +balls[i]);
}
System.out.println(" And the bonus ball is " +balls[6]);
int Payout = 0;
if (matching == 3)
{
System.out.println("Your payout was: R57");
}
else if (matching == 4)
{
System.out.println("Your payout was: R1033");
}
else if (matching == 5)
{
if (bonusMatch = true)
{
System.out.println("Your payout was: R2300000");
}
else
{
System.out.println("Your payout was: R55491");
}
}
else if (matching == 6)
{
System.out.println("Your payout was: R14000000");
}
}
答案 0 :(得分:0)
int b = (int)(Math.random()*6 + 1);
如果b
是相同的两倍(它是随机的,它会发生并且会发生),你有一个无限循环(keepLooking = true
,因为你在你的b
找到了inputtype = np.dtype(inputdata[c]).type
表,你迭代而不改变任何东西)。
无论你想要实现什么(老实说,你的代码毫无意义,创建具有有意义名称的方法,避免错综复杂的循环,简短的重构),对你的错误,而不是Netbeans。
答案 1 :(得分:0)
请使用“如果”循环而不是“而”循环,您将获得您想要的输出!!即, while(keepLooking)而是使用 if(keepLooking)