Question: Integer applicantAge is read from input. Use multiple exception handlers to: Catch an InputMismatchException and output Input type error: Integer required when applicantAge is not

Integer applicantAge is read from input. Use multiple exception handlers to:
Catch an InputMismatchException and output "Input type error: Integer required" when applicantAge is not an integer.
Catch an Exception and output the Exception's message when applicantAge is negative.
End each output with a newline. import java.util.Scanner;
import java.util.InputMismatchException;
public class ApplicantAge {
public static void main(String[] args){
Scanner scnr = new Scanner(System.in);
int applicantAge;
try {
applicantAge = scnr.nextInt();
if (applicantAge <0){
throw new Exception("Value error: Nonnegative value required");
}
System.out.print("Valid input: ");
System.out.println("Applicant's age is "+ applicantAge);
}
/* Your code goes here */
}
}

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 Databases Questions!