Write a program that deliberately contains an endless or infinite while loop. The loop should generate multiplication questions with single digit random integers. Users can answer the questions and get immediate feedback. After each question, the user should be able to stop the questions and get an overall result. See Example Output.

Respuesta :

Answer:

The Java code is given below with appropriate variable names for better understanding

Explanation:

import java.util.Random;

import java.util.Scanner;

public class MultiplicationQuestions {

   public static void main(String[] args) {

       Scanner scan = new Scanner(System.in);

       Random rand = new Random();

       int n1, n2, result, total = 0, correct = 0;

       char ch = 'y';

       while(ch == 'y'){

           n1 = 1 + rand.nextInt(9);

           n2 = 1 + rand.nextInt(9);

           System.out.print("What is "+n1+" * "+n2+" ? ");

           result = scan.nextInt();

           if(result==n1*n2){

               System.out.println("Correct. Nice work!");

               correct++;

           }

           else{

               System.out.println("Incorrect. The product is "+(n1*n2));

           }

           System.out.print("Want more questions y or n ? ");

           ch = scan.next().charAt(0);

           total++;

       }

       System.out.println("You scored "+correct+" out of "+total);

   }

}