import java.util.Scanner;
public class Main {
public static void main(String[] args) {
System.out.println("Welcome to Number Guessing Game:");
System.out.println("Please guess the number b/w 1-20 !");
double randomNumber = Math.floor(Math.random()*20+1);
var scanner = new Scanner(System.in);
System.out.print("Enter Your Guess: ");
int guess = scanner.nextInt();
int guessCount = 1;
int guessLimit = 3;
if(guess > 0) {
while (guessCount < guessLimit) {
if (guess < randomNumber) {
System.out.println("Your Guess is Low");
System.out.print("Enter Another guess: ");
guess = scanner.nextInt();
} else if (guess > randomNumber) {
System.out.println("Your Guess is High");
System.out.print("Enter Another guess: ");
guess = scanner.nextInt();
}
guessCount++;
}
if (guess == randomNumber) {
System.out.println("YOU WIN!");
System.out.println("Correct guess is " + randomNumber);
} else {
System.out.println("Sorry! You're Out of Guesses");
System.out.println("Correct Answer is " + randomNumber);
}
}
else {
System.out.println("Restart the Game and Enter Positive Value!");
System.out.println("Exit");
}
}
}