浏览代码

Updated to satisfy consecutive number condition

Kris Blassingame 6 年前
父节点
当前提交
a724cb9803
共有 3 个文件被更改,包括 9 次插入12 次删除
  1. 二进制
      Main.class
  2. 8
    11
      Main.java
  3. 1
    1
      package.bluej

二进制
Main.class 查看文件


+ 8
- 11
Main.java 查看文件

@@ -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!");

+ 1
- 1
package.bluej 查看文件

@@ -2,7 +2,7 @@
2 2
 editor.fx.0.height=722
3 3
 editor.fx.0.width=945
4 4
 editor.fx.0.x=229
5
-editor.fx.0.y=114
5
+editor.fx.0.y=115
6 6
 objectbench.height=297
7 7
 objectbench.width=504
8 8
 package.divider.horizontal=0.5997652582159625