Problem: A Simple Math Learning Tool
Suppose you want to develop a program to let a first-grader
practice addition. The program randomly generates two single-digit integers, number1 and number2, and displays to the student a question such as “What is 7+9?”, as shown
in the sample run. After the student types the answer, the program displays a
message to indicate whether it is true or false.
File name :
AdditionQuiz.java
import java.util.Scanner;
public class AdditionQuiz {
public static void
main(String[] args) {
int number1 = (int)(System.currentTimeMillis() % 10);
int number2 = (int)(System.currentTimeMillis() * 7 %
10);
// Create a Scanner
Scanner input = new
Scanner(System.in);
System.out.print("What
is " + number1 + " + " + number2 + "? ");
int answer = input.nextInt();
System.out.println(number1 +
" + " + number2 + " = " + answer + " is " +
(number1 + number2 == answer));
}
}