| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- import java.util.*;
- public class console
- {
- public static void main(String[] args){
-
- //Get random # and start counter of guesses
- int counter = 0;
- int max = 10;
- int min = 1;
- int range = max - min + 1;
- int number = 0;
- int guess = 0;
-
- for (int i = 0; i < 10; i++) {
- number = (int)(Math.random() * range) + min; }
-
- Scanner in = new Scanner(System.in);
- System.out.print("Take a guess between 1-10");
-
- while (in.hasNextInt() == true) {
-
- counter++;
-
- guess = in.nextInt();
-
- if (guess == number) {
- System.out.print("Correct Guess!");
- }
- else if (guess < number && guess <= 10 && guess != 0){
- System.out.print("Too Small. Try Again!");
- } else if (guess > number && guess <= 10){
- System.out.print("Too Large. Try Again!");
- } else {
- System.out.print("Oops! Please enter a number between 1 and 10");
- }; };
- if (in.hasNextInt() == false && guess != number) {
- int guesses = range - counter;
- System.out.print("Thanks for playing! You were " + guesses + " away from guessing the correct answer! Otherwise it would have taken at least 10 tries.");
- in.close();
- } else {
- System.out.print("Thanks for playing and congrats on guessing correct!");
- in.close();
- };};
-
- }
|