Hi I'm currently having trouble throwing exceptions on my guessing game code. I want to put an exception for string input (instead of int) and also an exception for entering a number beyond the limit(50). Thanks.
public static void main (String[] args)
{
Random ran = new Random();
int numberToGuess = ran.nextInt(50)+1;
int numberOfTries = 0;
Scanner input = new Scanner (System.in);
int guess;
boolean win = false;
while (win == false)
{
System.out.println("Guess a number from 1 to 50!");
guess = input.nextInt();
numberOfTries++;
if (guess == numberToGuess)
{
win = true;
}
else if (guess < numberToGuess)
{
System.out.println("Too low. Try again.");
}
else if (guess > numberToGuess)
{
System.out.println("Too high. Try again.");
}
}
System.out.println("You got it in " + numberOfTries + " attempt(s)!");
}