-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGuess.java
27 lines (24 loc) · 788 Bytes
/
Guess.java
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
import java.util.*;
class Lab_1 {
public static void main(String[] args) {
Random rand = new Random();
Scanner scan = new Scanner(System.in);
int secretNum = rand.nextInt(11);
int guessNum = 0;
int guess = 0;
while (guess != secretNum){
System.out.println("Enter your guess: ");
guessNum += 1;
guess = Integer.parseInt(scan.nextLine());
if (guess<secretNum){
System.out.println("Your guess is too low.");
}
else if (guess>secretNum){
System.out.println("Your guess is too high.");
}
else {
System.out.println("You got it in " + guessNum + " guesses!");
}
}
}
}