Arrays not matching correctly
        Posted  
        
            by Nick Gibson
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Nick Gibson
        
        
        
        Published on 2010-06-03T13:33:16Z
        Indexed on 
            2010/06/03
            13:34 UTC
        
        
        Read the original article
        Hit count: 291
        
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
© Stack Overflow or respective owner