forked from HarryDulaney/intro-to-java-programming
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExercise03_02.java
37 lines (24 loc) · 1.02 KB
/
Exercise03_02.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package ch_03;
import java.util.Scanner;
/**
* 3.2 (Game: add three numbers) The program in Listing 3.1, AdditionQuiz.java, generates
* two integers and prompts the user to enter the sum of these two integers.
* Revise the program to generate three single-digit integers and prompt the user to
* enter the sum of these three integers.
*
*/
public class Exercise03_02 {
public static void main(String[] args) {
int a = (int) (System.currentTimeMillis() % 10);
int b = (int) (System.currentTimeMillis() / 7 % 10);
int c = (int) (System.currentTimeMillis() / 5 % 10);
int correctAnswer = a + b + c;
Scanner input = new Scanner(System.in);
System.out.print("Fill in your answer and then press enter: " + a + " + " + b + " + " + c + " = ");
int userAnswer = input.nextInt();
if (userAnswer == correctAnswer) {
System.out.println("Congrats! That is correct!");
} else
System.out.println("That is incorrect, please try again");
}
}