java problem
This example creates a program to let a first grader practice additions. write. a program that randomly generates two single-digit integers number1 and number2 and displays a question such as “What is 7 + 9?” to the student. After the student types the answer, the program displays a message to indicate whether the answer is true or false. use boolean and math random
//Required JAVA code
import java.util.*;
public class Main
{
public static void main(String[] args) {
Random r= new Random();
Scanner sc= new Scanner(System.in);
int n1= r.nextInt(10);
int n2= r.nextInt(10);
System.out.println("What is "+n1+" + "+n2+" ?");
int res=sc.nextInt();
boolean rs;
if(res== (n1+n2))
rs=true;
else
rs=false;
System.out.println(rs);
}
}
Get Answers For Free
Most questions answered within 1 hours.