1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- import java.util.*;
-
- public class Main {
- public static void main(String[] args){
- Scanner in = new Scanner(System.in);
- System.out.println("WELCOME! Guess a number between 1 and 49:");
- int inputtedNumber = in.nextInt();
- int previousInputNumber = 0;
-
- int randomNumber = (int) (Math.random()*50);
-
- int numberOfGuesses = 0;
-
-
- String tryOrTries = "";
- if (numberOfGuesses == 1){
- tryOrTries ="try!";
- }
- else {
- tryOrTries = "tries!";
- }
-
- while (true){
- if(inputtedNumber < 1 || inputtedNumber > 49){
- System.out.println("Guess a number between 1 and 49!");
- }
- else if(inputtedNumber < randomNumber && inputtedNumber > 0 && inputtedNumber < 50){
-
- if (inputtedNumber != previousInputNumber){
- numberOfGuesses = numberOfGuesses + 1;
- }
- System.out.println("TOO SMALL! Try again");
- }
- else if (inputtedNumber > randomNumber && inputtedNumber > 0 && inputtedNumber < 50){
-
- if (inputtedNumber != previousInputNumber){
- numberOfGuesses = numberOfGuesses + 1;
- }
- System.out.println("TOO LARGE! Try again!");
- }
- else if(inputtedNumber == randomNumber){
-
- if (inputtedNumber != previousInputNumber){
- numberOfGuesses = numberOfGuesses + 1;
- }
- System.out.println("CORRECT GUESS! You guessed the correct answer after " + numberOfGuesses + " "+ tryOrTries);
- break;
- }
- previousInputNumber = inputtedNumber;
- inputtedNumber = in.nextInt();
- }
- }
- }
|