In: Computer Science
Write a program for multiplication quiz.
It displays to the student a question such as “What is 5 × 19?”. After the student enters the answer, the program displays a message indicating whether it is correct.
Note: you can use Math.random() to obtain a random integer value between 0 and 100.
JAVA
//MathQuiz.java
import java.util.Random;
import java.util.Scanner;
public class MathQuiz {
public static void main(String[] args) {
System.out.println("Welcome to multiplication quiz!\n\n");
// random for generating random number
Random rand = new Random();
Scanner scanner = new Scanner(System.in);
int num1, num2;
while (true) {
// generating random number between 0 and 100
num1 = rand.nextInt(99) + 1;
num2 = rand.nextInt(99) + 2;
System.out.println(String.format("What is %d × %d?", num1, num2));
// scanning the user answer
int userAnswer = scanner.nextInt();
// computing the correct answer
int correctAnswer = num1 * num2;
// comparing the answer and printing result accordingly
if (userAnswer == correctAnswer) {
System.out.println("Correct Answer");
}
else System.out.println("Sorry! Incorrect Answer, Correct Answer is : "+correctAnswer);
// asking if want to play again
System.out.print("Do you continue want to play[y/n]? ");
String choice = scanner.next().toLowerCase().trim();
if(choice.charAt(0)=='n'){
System.out.println("Thanks for Playing!!!");
break;
}
System.out.println();
}
}
}
//OUTPUT

Please do let me know if u have any concern...