Arrays not matching correctly
- by Nick Gibson
userAnswer[] holds the string of the answer the user types in and is comparing it to answers[] to see if they match up and then spits out correct or wrong. j is equal to the question number. So if j was question 6, answers[j] should refer to answers[6] right?
Then userAnswer[6] should compare to answers[6] and match if its correct. But its giving me wrong answers and displaying the answer I typed as correct.
int abc, loopCount = 100;
int j = quesNum, overValue, forLoop = 100;
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)
{
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
}//if
}//for