You are on page 1of 4

package main_class;

import java.util.Random;
import java.util.Scanner;
import java.util.Arrays;

public class Multiplication_Exercise {

public static void main(String[] args)

{Scanner input = new Scanner(System.in);


Random rand = new Random();

int upperbound = 9 , upperbound2 = 9 , answer ;


int number = rand.nextInt(upperbound);
int number2 = rand.nextInt(upperbound2);
int realanswer;
int counter = -1 ;
int choice = 1;

//String[] praiseMessage = {" Correct ", " Splendid " ," Good Job ", " Brilliant "};
String[] encourageMessage = {" Incorrect ", " Try Again ", " Close, try again ", " Check your
answer again "};

//String msg = Arrays.toString(praise message); // try to make it readable

while (choice > 0)

{ choice++;

System.out.println( + number + " times " + number2 );

realanswer = number * number2;

System.out.print(" Enter the answer: ");


answer = input.nextInt();

System.out.println(" The answer is " + answer);

while (answer != realanswer )


{

//System.out.println(encourageMessage[0]);

counter++;

if (counter == 0)
System.out.println(encourageMessage[0]);
else if (counter == 1)
System.out.println(encourageMessage[1]);
else if (counter == 2 )
System.out.println(encourageMessage[2]);

else System.out.println(encourageMessage [3]);

System.out.print(" Enter the answer: ");


answer = input.nextInt();

System.out.println(" The answer is " + answer);

}
}

if (answer == realanswer)
{
System.out.println(" Correct");

System.out.println(" Do you wish to continue ? (Press 1 to continue or 0 to exit)");


choice = input.nextInt();
}
else if (answer != realanswer);

if (choice ==1);

/*while (answer != realanswer)


{
System.out.print(" Your answer is incorrect ");
}*/
}

}
I had a problem where the question is not randomize again after we wish to continue the
question, means that the same question is keep repeated

You might also like