#30 ZCW-TooLargeTooSmall-BlueJ/

Открыто
jtinkler хочет смерджить 1 коммит(ов) из jtinkler/ZCW-TooLargeTooSmall-BlueJ:master в master
1 измененных файлов: 44 добавлений и 5 удалений
  1. 44
    5
      Main.java

+ 44
- 5
Main.java Просмотреть файл

@@ -1,9 +1,48 @@
1 1
 /**
2 2
  * Created by iyasuwatts on 10/17/17.
3 3
  */
4
-public class Main {
4
+ import java.util.*;
5 5
 
6
-    public static void main(String[] args){
7
-        
8
-    }
9
-}
6
+
7
+
8
+ public class NumberGame
9
+ {
10
+
11
+     public static void main (String [] args)
12
+     {
13
+         // initialise  variables
14
+         Random randomNumber = new Random();
15
+         int numberGuess = randomNumber.nextInt(10);
16
+         int numberOfTries = 0;
17
+         Scanner input = new Scanner(System.in);
18
+         int guess;
19
+         boolean win = false;
20
+
21
+         while (win == false) {
22
+
23
+         System.out.println("Guess a number between 1 and 10");
24
+
25
+         guess = input.nextInt();
26
+         numberOfTries++;
27
+
28
+         if (guess == numberGuess) {
29
+
30
+             win = true;
31
+         }
32
+         else if (guess < numberGuess) {
33
+             System.out.println("Your guess is too small");
34
+         }
35
+
36
+         else if  (guess > numberGuess) {
37
+             System.out.println("Your guess is too large");
38
+         }
39
+       }
40
+
41
+       System.out.println("You win!");
42
+       System.out.println("The number was " + numberGuess);
43
+       System.out.println("It only took you " + numberOfTries + " tries");
44
+     }
45
+ }
46
+
47
+
48
+