java multiplication questions Randomly generate two integers

java multiplication questions. Randomly generate two integers between 1 and 12, print out the multiplication question and ask user to put in answer, your program then check the answer and record the score. Continue with the questions until user ends the quiz. Then print out the overall score.
Sample output:
What is 8 * 2 ( Enter answer or -1 to quit) ? 16
Correct.
What is 12*11 ( Enter answer or -1 to quit)? 120
Incorrect.
What is 3*5 ( Enter answer or -1 to quit)? 15
Correct
What is 4*9 ( Enter answer or -1 to quit)? -1
Total # of questions: 3
Total # of correct answers: 2
Percentage correct: 66.7%
java multiplication questions. Randomly generate two integers between 1 and 12, print out the multiplication question and ask user to put in answer, your program then check the answer and record the score. Continue with the questions until user ends the quiz. Then print out the overall score.
Sample output:
What is 8 * 2 ( Enter answer or -1 to quit) ? 16
Correct.
What is 12*11 ( Enter answer or -1 to quit)? 120
Incorrect.
What is 3*5 ( Enter answer or -1 to quit)? 15
Correct
What is 4*9 ( Enter answer or -1 to quit)? -1
Total # of questions: 3
Total # of correct answers: 2
Percentage correct: 66.7%
java multiplication questions. Randomly generate two integers between 1 and 12, print out the multiplication question and ask user to put in answer, your program then check the answer and record the score. Continue with the questions until user ends the quiz. Then print out the overall score.
Sample output:
What is 8 * 2 ( Enter answer or -1 to quit) ? 16
Correct.
What is 12*11 ( Enter answer or -1 to quit)? 120
Incorrect.
What is 3*5 ( Enter answer or -1 to quit)? 15
Correct
What is 4*9 ( Enter answer or -1 to quit)? -1
Total # of questions: 3
Total # of correct answers: 2
Percentage correct: 66.7%

Solution

import java.util.*;
import java.lang.*;
import java.io.*;


class MultiplicationQuiz
{
   public static void main (String[] args) throws java.lang.Exception
   {
       int c=0;
       int numQues=0,corAns=0;
       do{
       int score=0;
       Random r = new Random();
int Low = 1;
int High = 13;
int num1 = r.nextInt(High-Low) + Low;

int num2 = r.nextInt(High-Low) + Low;
System.out.println(\"What is \" +num1 + \" * \" +num2+ \" ?(Enter -1 to quit )\");
Scanner s=new Scanner(System.in);
c=s.nextInt();

int res=num1*num2;
if(c==res)
{
corAns++;
score++;
}

numQues++;
       }while(c!=-1);

numQues=numQues-1;
       System.out.println(\"Total # of questions:\" + numQues);
       System.out.println(\"Total # of correct answers:\" + corAns);
double percentCorr=(corAns*100)/numQues;
       System.out.println(\"Percentage Correct: \" + percentCorr);
  
   }
}

OUTPUT:

What is 5 * 7 ?(Enter -1 to quit )
35
What is 6 * 2 ?(Enter -1 to quit )
12
What is 2 * 9 ?(Enter -1 to quit )
34
What is 2 * 2 ?(Enter -1 to quit )
-1
Total # of questions:3
Total # of correct answers:2
Percentage Correct: 66.66666666666667

 java multiplication questions. Randomly generate two integers between 1 and 12, print out the multiplication question and ask user to put in answer, your progr
 java multiplication questions. Randomly generate two integers between 1 and 12, print out the multiplication question and ask user to put in answer, your progr

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site