-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem3.java
More file actions
32 lines (25 loc) · 991 Bytes
/
Problem3.java
File metadata and controls
32 lines (25 loc) · 991 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
28
29
30
31
32
/* Write a Java program that prompts the user to enter integers from the keyboard one at a time. The
program stops reading integers once the user enters the same value three times consecutively (meaning three
times, one after the other). Once input is completed the program is to display the message "Same entered 3
in a row". */
import java.util.Scanner;
public class Problem3 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int temp2 = -1;
boolean repeat = true;
int temp = -1;
while (repeat) {
System.out.println("Enter an integer: ");
int number = input.nextInt();
if (number == temp) {
if (number == temp2) {
repeat = false;
System.out.println("This integer has been entered 3 times in a row");
}
temp2 = number;
}
temp = number;
}
}
}