此循環正常工作,但有時會過早退出。我在其中設置了一段代碼,以便查看隨機數。它僅關閉過早當隨機數是等於最高編號的問題,用戶輸入循環過早退出
(例...用戶想要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