|
@@ -0,0 +1,57 @@
|
|
1
|
+
|
|
2
|
+/**
|
|
3
|
+ * Write a description of class Main here.
|
|
4
|
+ *
|
|
5
|
+ * @author (your name)
|
|
6
|
+ * @version (a version number or a date)
|
|
7
|
+ */
|
|
8
|
+import java.util.Scanner;
|
|
9
|
+import java.util.*;
|
|
10
|
+public class Main
|
|
11
|
+{
|
|
12
|
+
|
|
13
|
+ public static void main(String[] args){
|
|
14
|
+ int numOfGuesses = 1;
|
|
15
|
+
|
|
16
|
+ Random randomNum = new Random();
|
|
17
|
+ int randNum = randomNum.nextInt(10)+1;
|
|
18
|
+ Scanner in = new Scanner(System.in);
|
|
19
|
+ System.out.print("Enter a number between 1 and 10 ");
|
|
20
|
+
|
|
21
|
+ int userNum = in.nextInt();
|
|
22
|
+ int newNum = 0;
|
|
23
|
+ while (userNum != randNum){
|
|
24
|
+ if (userNum > randNum){
|
|
25
|
+ System.out.print("Your number is TOO BIG! ");
|
|
26
|
+ if(userNum != newNum){
|
|
27
|
+
|
|
28
|
+ //newNum = in.nextInt();
|
|
29
|
+ numOfGuesses++;
|
|
30
|
+ }
|
|
31
|
+
|
|
32
|
+ userNum = in.nextInt();
|
|
33
|
+ }
|
|
34
|
+ else if(userNum < randNum){
|
|
35
|
+ System.out.print("Your number is TOO SMALL! ");
|
|
36
|
+ if(userNum != newNum){
|
|
37
|
+
|
|
38
|
+ //newNum = in.nextInt();
|
|
39
|
+ numOfGuesses++;
|
|
40
|
+ }
|
|
41
|
+
|
|
42
|
+ userNum = in.nextInt();
|
|
43
|
+
|
|
44
|
+ }
|
|
45
|
+
|
|
46
|
+ }
|
|
47
|
+ System.out.println("Correct!");
|
|
48
|
+ System.out.println("It took " + numOfGuesses + "trys");
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+ }
|
|
57
|
+}
|