|
@@ -8,26 +8,23 @@ public class Main {
|
8
|
8
|
Scanner input = new Scanner(System.in);
|
9
|
9
|
|
10
|
10
|
int mysteryNum = (int) Math.floor(Math.random() * 100 + 1);
|
11
|
|
- int numOfGuesses =+ 1;
|
|
11
|
+ int numOfGuesses = 0;
|
|
12
|
+ int prevGuess = 0;
|
|
13
|
+ int userNum = 0;
|
12
|
14
|
System.out.println("Hey, you! Pick a number between 1 and 100: ");
|
13
|
|
- int userNum = input.nextInt();
|
14
|
|
-
|
|
15
|
+
|
15
|
16
|
while (userNum != mysteryNum) {
|
|
17
|
+ userNum = input.nextInt();
|
16
|
18
|
if (userNum < mysteryNum) {
|
17
|
19
|
System.out.println("Too small! Guess again!");
|
18
|
|
- numOfGuesses++;
|
19
|
|
- userNum = input.nextInt();
|
20
|
20
|
}
|
21
|
|
-
|
22
|
21
|
else if (userNum > mysteryNum) {
|
23
|
22
|
System.out.println("Too large! Guess again!");
|
24
|
|
- userNum = input.nextInt();
|
25
|
|
- numOfGuesses++;
|
26
|
23
|
}
|
27
|
|
- else{
|
28
|
|
-
|
|
24
|
+ if (prevGuess != userNum) {
|
|
25
|
+ numOfGuesses++;
|
29
|
26
|
}
|
30
|
|
-
|
|
27
|
+ prevGuess = userNum;
|
31
|
28
|
}
|
32
|
29
|
System.out.println("Correct guess!");
|
33
|
30
|
System.out.println("It took you " + numOfGuesses + " guess(es) to figure it out!");
|