Bladeren bron

finished TooLargeTooSmall

Roy 6 jaren geleden
bovenliggende
commit
124b42082a
4 gewijzigde bestanden met toevoegingen van 69 en 1 verwijderingen
  1. BIN
      Main.class
  2. 5
    0
      Main.ctxt
  3. 32
    1
      Main.java
  4. 32
    0
      package.bluej

BIN
Main.class Bestand weergeven


+ 5
- 0
Main.ctxt Bestand weergeven

@@ -0,0 +1,5 @@
1
+#BlueJ class context
2
+comment0.target=Main
3
+comment1.params=args
4
+comment1.target=void\ main(java.lang.String[])
5
+numComments=2

+ 32
- 1
Main.java Bestand weergeven

@@ -1,9 +1,40 @@
1 1
 /**
2 2
  * Created by iyasuwatts on 10/17/17.
3 3
  */
4
+import java.util.Scanner;
4 5
 public class Main {
5 6
 
6 7
     public static void main(String[] args){
7
-        
8
+        int num = (int)((Math.random()*10)%20)+1;
9
+        //System.out.println(num);
10
+        System.out.println("Guess a number between 1 and 20");
11
+        int currentGuess;
12
+        int previousGuess =0;
13
+        int numGuess =0;
14
+        Boolean guess = true;
15
+
16
+        while (guess){
17
+            Scanner in = new Scanner(System.in);
18
+            currentGuess = in.nextInt();
19
+
20
+            if (currentGuess == num){
21
+                System.out.println("Correct Guess");
22
+                guess = false;
23
+            }
24
+            else if (currentGuess > num){
25
+                System.out.println("too large");
26
+
27
+            }
28
+            else {
29
+                System.out.println("too small");
30
+
31
+            }
32
+            if(!(previousGuess == currentGuess)){
33
+                numGuess++;
34
+            }
35
+            previousGuess = currentGuess;
36
+            // i++;
37
+        }
38
+        System.out.println(numGuess);
8 39
     }
9 40
 }

+ 32
- 0
package.bluej Bestand weergeven

@@ -0,0 +1,32 @@
1
+#BlueJ package file
2
+editor.fx.0.height=722
3
+editor.fx.0.width=741
4
+editor.fx.0.x=537
5
+editor.fx.0.y=24
6
+objectbench.height=101
7
+objectbench.width=461
8
+package.divider.horizontal=0.6
9
+package.divider.vertical=0.8007380073800738
10
+package.editor.height=427
11
+package.editor.width=674
12
+package.editor.x=294
13
+package.editor.y=112
14
+package.frame.height=600
15
+package.frame.width=800
16
+package.numDependencies=0
17
+package.numTargets=1
18
+package.showExtends=true
19
+package.showUses=true
20
+project.charset=UTF-8
21
+readme.height=58
22
+readme.name=@README
23
+readme.width=47
24
+readme.x=10
25
+readme.y=10
26
+target1.height=50
27
+target1.name=Main
28
+target1.showInterface=false
29
+target1.type=ClassTarget
30
+target1.width=80
31
+target1.x=70
32
+target1.y=10