-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuess.java
More file actions
30 lines (25 loc) · 790 Bytes
/
Guess.java
File metadata and controls
30 lines (25 loc) · 790 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
package Practice.Assignments;
import java.util.*;
import java.lang.*;
public class Guess {
public static void main(String[] args) {
Scanner number = new Scanner(System.in);
Random random = new Random();
int value = 1 + random.nextInt(10);
int guess = 1;
while (guess > 0) {
System.out.print("guess my number (range: 1 - 10): ");
int guessNumber = number.nextInt();
if (guessNumber < value) {
System.out.println("Too Low! Try Again");
}
else if(guessNumber > value) {
System.out.println("Too High! Try Again");
}
else {
System.out.println("Perfect");break;
}
guess++;
}
}
}