-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathMain.java
More file actions
29 lines (27 loc) · 982 Bytes
/
Main.java
File metadata and controls
29 lines (27 loc) · 982 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
import java.util.Random;
import java.util.Scanner;
/**
* Created by iyasuwatts on 10/17/17.
*/
public class Main {
public static void main(String[] args) {
Scanner userInput = new Scanner(System.in);
Random rand = new Random();
int count = 0;
int mysteryNum = rand.nextInt(1000);
System.out.println("Please guess to find the mystery number. The mystery number is between 0 and 1000.");
while (true) {
int userNum = userInput.nextInt();
count++;
if (userNum > mysteryNum) {
System.out.println("Too large. Please guess again.");
} else if (userNum < mysteryNum) {
System.out.println("Too small. Please guess again.");
} else if (userNum == mysteryNum) {
System.out.println("Correct guess!");
System.out.println("It took you " + count +" guesses.");
break;
}
}
}
}