Question: language: java using exception handling using InputMisMatch how do you loop a question inside a menu until user puts correct datatype input.Also, the menu should
language: java using exception handling using InputMisMatch
how do you loop a question inside a menu until user puts correct datatype input.Also, the menu should loop too until the use picks 4, where user exits program.
How do you do this with a menu system using try and catch block. so each time the use input is not correct data type, that question is repeated until user gets correct.
I know the format for exception handling with loop is like this:
do {
try{
} catch(InputMismatchException ex) {
} }while ();
for example.: user has a menu
1. (int) age 2. (int)Phone number 3. (string) city 4. Exit the program
In each menu:
when you pick 1.
enter age:
when you pick 2:
enter phoneNumber:
when you pick 3:
enter city:
when you pick 4: it should say you are exiting program!
if user puts anything else then int for entering age. the statement enter age should be repeated where user can input the age again.
if user puts anything else then int for entering phone number. the statement enter phone number should be repeated where user can input the phone number again
if user puts anything else then for entering city, the statement enter city should be repeated where the user can input the city again.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
