-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGuess.java
29 lines (25 loc) · 843 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
27
28
29
import java.util.Random;
import java.util.Scanner;
class Guess {
public static void main(String[] args) {
Random r = new Random();
int rand = r.nextInt(10) + 1;
int numGuesses = 0;
int guess = 0;
while (guess != rand) {
Scanner scan = new Scanner(System.in);
guess = Integer.parseInt(scan.nextLine());
numGuesses += 1;
if (guess < rand) {
System.out.println("Your guess is too low.");
}
if (guess > rand) {
System.out.println("Your guess is too high.");
}
if (guess == rand) {
System.out.println("You got it!!");
}
}
System.out.println("It took you " + numGuesses + " guesses.");
}
}