Question: Exercise 2. ( Problem: An Advanced Math Learning Tool) The Math subtraction learning tool program generates just one question for each run. To create one

Exercise 2. (Problem: An Advanced Math Learning Tool) The Math subtraction learning tool program generates just one question for each run. To create one question, the program randomly generates two integers between 0 and 99, say, number1 and number2, and displays a question such as What is number1 * number2? to the student, namely asking for the product of the two numbers. After the student types the answer, the program displays a message to indicate whether the answer is true or false. You can use a loop to generate questions repeatedly. Write a Java program that generates five questions and reports the number of the correct answers after a student answers all five questions.

How to create the loop for the program? here is what i have

Scanner input = new Scanner(System.in);

int number1 = (int)(Math.random() * 100);

int number2 = (int)(Math.random() * 100);

if (number1 < number2) {

int temp = number1;

number1 = number2;

number2 = temp;

}

System.out.println("What is " + number1 + "-" + number2 + "?");

int answer = input.nextInt();

if (number1 - number2 == answer)

System.out.println("YOU ARE CORRECT, YOU GET A STAR!");

else

System.out.println("Your answer is wrong, You get no star. " + number1 + " - " + number2 + " should be " + (number1 -number2));

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!