|
@@ -9,44 +9,26 @@ public class Main {
|
9
|
9
|
Scanner in = new Scanner(System.in);
|
10
|
10
|
System.out.println("Enter a random number between 1 and 10: ");
|
11
|
11
|
Random number = new Random();
|
12
|
|
- int x = (number.nextInt(10)+1);
|
13
|
|
- //int x = (int)(random*10);
|
14
|
|
- int y;
|
|
12
|
+ int currentGuess = (number.nextInt(10)+1);
|
|
13
|
+ int currentValue;
|
15
|
14
|
int count = 0;
|
16
|
|
- int prev = 0;
|
|
15
|
+ int previousValue = 0;
|
17
|
16
|
boolean win = false;
|
18
|
|
-
|
19
|
|
- // while ( win == false)
|
20
|
|
- // {
|
21
|
|
- // if (y == x){
|
22
|
|
- // win = true;
|
23
|
|
- // count++;
|
24
|
|
- // } else if (y > x) {
|
25
|
|
- // System.out.println ("Too Big");
|
26
|
|
- // if (y != prev) {
|
27
|
|
- // count++;
|
28
|
|
- // prev=y;}
|
29
|
|
- // } else if ( y < x) {
|
30
|
|
- // System.out.println ("Too Small");
|
31
|
|
- // if (y != prev) {
|
32
|
|
- // count++;
|
33
|
|
- // prev=x;}
|
34
|
|
- // }
|
35
|
17
|
|
36
|
18
|
while (win == false) {
|
37
|
|
- y = in.nextInt();
|
38
|
|
- if (y != prev) {
|
|
19
|
+ currentValue = in.nextInt();
|
|
20
|
+ if (currentValue != previousValue) {
|
39
|
21
|
count++;
|
40
|
|
- }
|
41
|
|
- if (y==x){
|
|
22
|
+ }
|
|
23
|
+ if (currentValue == currentGuess){
|
42
|
24
|
System.out.println("Correct guess!");
|
43
|
25
|
break;
|
44
|
|
- } else if (y < x){
|
|
26
|
+ } else if (currentValue < currentGuess){
|
45
|
27
|
System.out.println("That guess is too small.");
|
46
|
28
|
} else {
|
47
|
29
|
System.out.println("That guess is too large.");
|
48
|
30
|
}
|
49
|
|
- prev = y;
|
|
31
|
+ previousValue = currentValue;
|
50
|
32
|
}
|
51
|
33
|
System.out.println("You Win!");
|
52
|
34
|
System.out.println("Number of counts to win: " + count);
|