|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+import java.util.*;
|
|
|
2
|
+public class console
|
|
|
3
|
+{
|
|
|
4
|
+ public static void main(String[] args){
|
|
|
5
|
+
|
|
|
6
|
+ //Get random # and start counter of guesses
|
|
|
7
|
+ int counter = 0;
|
|
|
8
|
+ int max = 10;
|
|
|
9
|
+ int min = 1;
|
|
|
10
|
+ int range = max - min + 1;
|
|
|
11
|
+ int number = 0;
|
|
|
12
|
+ int guess = 0;
|
|
|
13
|
+
|
|
|
14
|
+ for (int i = 0; i < 10; i++) {
|
|
|
15
|
+ number = (int)(Math.random() * range) + min; }
|
|
|
16
|
+
|
|
|
17
|
+ Scanner in = new Scanner(System.in);
|
|
|
18
|
+ System.out.print("Take a guess between 1-10");
|
|
|
19
|
+
|
|
|
20
|
+ while (in.hasNextInt() == true) {
|
|
|
21
|
+
|
|
|
22
|
+ counter++;
|
|
|
23
|
+
|
|
|
24
|
+ guess = in.nextInt();
|
|
|
25
|
+
|
|
|
26
|
+ if (guess == number) {
|
|
|
27
|
+ System.out.print("Correct Guess!");
|
|
|
28
|
+ }
|
|
|
29
|
+ else if (guess < number && guess <= 10 && guess != 0){
|
|
|
30
|
+ System.out.print("Too Small. Try Again!");
|
|
|
31
|
+ } else if (guess > number && guess <= 10){
|
|
|
32
|
+ System.out.print("Too Large. Try Again!");
|
|
|
33
|
+ } else {
|
|
|
34
|
+ System.out.print("Oops! Please enter a number between 1 and 10");
|
|
|
35
|
+ }; };
|
|
|
36
|
+ if (in.hasNextInt() == false && guess != number) {
|
|
|
37
|
+ int guesses = range - counter;
|
|
|
38
|
+ System.out.print("Thanks for playing! You were " + guesses + " away from guessing the correct answer! Otherwise it would have taken at least 10 tries.");
|
|
|
39
|
+ in.close();
|
|
|
40
|
+ } else {
|
|
|
41
|
+ System.out.print("Thanks for playing and congrats on guessing correct!");
|
|
|
42
|
+ in.close();
|
|
|
43
|
+ };};
|
|
|
44
|
+
|
|
|
45
|
+ }
|