Question: Select the missing expression in the code fragment below. The method should continue to prompt the user for a valid integer value until one is

Select the missing expression in the code fragment below. The method should continue to prompt the user for a valid integer value until one is entered. The method returns the final value entered.
public static int getAge()
{
boolean done = false;
Scanner console = new Scanner(System.in);
int value =0;
while (!done)
{
try
{
System.out.print("Please enter your age in years: ");
value = console.nextInt();
done = true;
}
_____________________
{
System.out.println("Invalid value. Try again.");
console.nextLine();
}
}
return value;
}
Question 30 options:
catch (IllegalArgumentException exception)
finally
catch (NumberFormatException exception)
catch (NoSuchElementException exception)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!