Brandon Defrancis 6 years ago
parent
commit
95a0fb30eb
1 changed files with 35 additions and 1 deletions
  1. 35
    1
      Main.java

+ 35
- 1
Main.java View File

1
 /**
1
 /**
2
  * Created by iyasuwatts on 10/17/17.
2
  * Created by iyasuwatts on 10/17/17.
3
  */
3
  */
4
+import java.util.*;
5
+
6
+
4
 public class Main {
7
 public class Main {
5
 
8
 
6
     public static void main(String[] args){
9
     public static void main(String[] args){
7
-        
10
+
11
+      Random randomNumber = new Random();
12
+      Scanner x = new Scanner(System.in);
13
+      int computerNumber = randomNumber.nextInt(10);
14
+      int numberOfTries = 0;
15
+      int success = 0;
16
+      int guess = 0;
17
+
18
+      while (success ==0){
19
+
20
+        System.out.println("Guess a number from 1 to 10");
21
+        guess = x.nextInt();
22
+        numberOfTries++;
23
+
24
+          if (guess < 1 || guess >10){
25
+            System.out.println("Invaled number. Try again");
26
+          }
27
+          else if (guess == computerNumber){
28
+            System.out.println("Congratulations your right! Only took you " + numberOfTries + " tries.");
29
+          }
30
+          else if (guess < computerNumber){
31
+            System.out.println("Too low! Try again.");
32
+          }
33
+          else if (guess > computerNumber){
34
+            System.out.println("Too high! Try again.");
35
+          }
36
+          if (guess == computerNumber){
37
+              break;
38
+            }
39
+}
40
+
41
+
8
     }
42
     }
9
 }
43
 }