此循环正常工作,但有时会过早退出。我在其中设置了一段代码,以便查看随机数。它仅关闭过早当随机数是等于最高编号的问题,用户输入循环过早退出
(例...用户想要10个问题,如果随机数为10的程序退出。)
我有不知道为什么,因为我有它设置,如果(随机数< =问题的数量)
for (int loop = 1; loop < loopCount; loop++)
{
aa = r.nextInt (10 + 1);
abc = (int) aa;
String[] userAnswer = new String[x];
JOptionPane.showMessageDialog (null, abc);
if (abc <= x)
{
for (overValue = 1; overValue < forLoop; overValue++);
{
userAnswer[j] = JOptionPane.showInputDialog (null, "Question " + quesNum + "\n" + questions[abc] + "\n\nA: " + a[abc] + "\nB: " + b[abc] + "\nC: " + c[abc] + "\nD: " + d[abc]);
if (userAnswer[j].equals (answers[j]))
{
JOptionPane.showMessageDialog (null, "Correct. \nThe Correct Answer is " + answers[abc]);
}
else
{
JOptionPane.showMessageDialog (null, "Wrong. \n The Correct Answer is " + answers[abc]);
}//else
}//for
}//if
}//for
如果过早关闭,循环无法正常工作。 – CheesePls 2010-06-03 13:35:33
看起来你已经选择了你的答案。但稍后,请学习如何提供有意义的变量名称。到底是什么,aa,abc和x? – Phil 2010-06-04 03:07:02