-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem13.java
More file actions
35 lines (28 loc) · 1.08 KB
/
Problem13.java
File metadata and controls
35 lines (28 loc) · 1.08 KB
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
/*Write a program that has the user enter integers between 0 and 9999 until the user enters some
integer twice. Your program then prints to the console window how many distinct integers were entered.
You may assume all integers entered by the user are between 0 and 9999. */
import java.util.Scanner;
public class Problem13 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int[] myArray = new int[9999];
boolean exiting = true;
int count = 0;
int userInput = -1;
for (int i = 0; i < myArray.length; i++) {
myArray[i] = -1;
}
do {
myArray[count] = userInput;
System.out.print("Enter an int between (0-9999): ");
userInput = input.nextInt();
count++;
for (int i = 0; i < myArray.length; i++) {
if (userInput == myArray[i]) {
exiting = false;
}
}
} while (exiting);
System.out.println("You entered " + (count - 1) + " value(s)");
}
}