forked from jsquared21/Intro-to-Java-Programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise_03_02.java
More file actions
executable file
·27 lines (23 loc) · 903 Bytes
/
Exercise_03_02.java
File metadata and controls
executable file
·27 lines (23 loc) · 903 Bytes
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
/*
(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.
*/
import java.util.Scanner;
public class Exercise_03_02 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
// Generate three random integers
int digit1 = (int)(Math.random() * 10);
int digit2 = (int)(Math.random() * 10);
int digit3 = (int)(Math.random() * 10);
// Prompt user to enter the sum of three integers
System.out.print(
"What is " + digit1 + " + " + digit2 + " + " + digit3 + "? ");
int answer = input.nextInt();
System.out.println(
digit1 + " + " + digit2 + " + " + digit3 + " = " + answer + " is " +
(digit1 + digit2 + digit3 == answer));
}
}