I am making a multiplication app for kids on Android. Here is the code I have:
import java.awt.*;
import java.math.*;
import javax.swing.*;
public class S1P4 extends JFrame
{
public static void main(String[] args){
int l = 0;
int x =(int)(Math.random()*100);
int y =(int)(Math.random()*10);
int answer = -1;
String answer3 = null;
int []anArray;
anArray = new int[20];
for ( int i=0; i < 20; i++)
{
if ( (i % 2)==0)
anArray[i]=(int)(Math.random()*100);
else
anArray[i]=(int)(Math.random()*10);
}
String answerString = "";
String rightAnswer = "";
for (l=0; l<20; l++)
{
rightAnswer = Integer.toString(anArray[l] * anArray[l+1]);
answerString = (JOptionPane.showInputDialog("The Problem is " + anArray[l] + " * " + anArray[l+1] + ", What is the answer? "));
while (answerString.equals(""))
answerString =JOptionPane.showInputDialog("Please type an answer to the problem: " + anArray[l] + " * " + anArray[l+1] + ", What is the answer? ");
while (!answerString.equals(rightAnswer))
answerString =JOptionPane.showInputDialog("Good try! but that's not it.. The problem again is: " + anArray[l] + " * " + anArray[l+1] + ", What is the answer? ");
}
for (int n=0; answerString != rightAnswer; n++){
if (anArray[l] == 1){
System.out.println("Congratulations! you got all the correct answers in "+ n + l +"tries!");
System.exit(0);}
else{
System.out.println("Error.");
}
}
}
Why won't this code work? I want it to print how many tries it took the user to get all the multiplication problems correct.
for (int n=0; answerString != rightAnswer; n++){
if (anArray[l] == 20){
System.out.println("Congratulations! you got all the correct answers in "+ n + l +"tries!");
System.exit(0);}
else{
System.out.println("Error.");
}
}
}