loop prematurely quitting
Posted
by Nick Gibson
on Stack Overflow
See other posts from Stack Overflow
or by Nick Gibson
Published on 2010-06-03T13:04:52Z
Indexed on
2010/06/03
13:14 UTC
Read the original article
Hit count: 164
This loop works fine but prematurely quits at times. I set a piece of code in it so that I can view the random number. It only closes prematurely when the random number is equal to the highest numbered question the user inputs
(Example...a user wants 10 questions, if the random number is 10 the program quits.)
I have no idea why since i have it set to if(random number <= the number of questions)
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
© Stack Overflow or respective owner