In: Computer Science
Write a java program (use value returning method) that gives simple math quizzes. The program should display two random integers from 1 to 100 that are to be added, such as:
47
+ 29
The program allows the user to enter the answer. If
the answer is correct, display “congratulations”. If the answer is
incorrect, the program should show the correct answer.
Your result should look like, for example:
47
+ 29
Enter your answer: 1
Wrong, the right answer is 76
Sample output:
The screenshots are attached below for reference.
Please follow them for proper indentation and output.
Program to copy:
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner inp=new
Scanner(System.in);
Random rand=new Random();
int n;
int r1,r2;
r1=rand.nextInt(100)+1;
r2=rand.nextInt(100)+1;//generate
two random numbers
System.out.println(" "+r1);
System.out.println("+"+r2);
System.out.print("Enter your
answer:");
n=inp.nextInt();//read answer from
user
if(n==(r1+r2))//check if same or
not
System.out.print("congratulations");
else
System.out.println("Wrong, the
right answer is "+(r1+r2));
}
}