Skip to content

Practice Problem 9

Seanti edited this page Mar 26, 2025 · 1 revision

Problem:

Ask the user to enter their age. If they enter non-numeric input, handle the error using try-catch and ask them to enter a valid number.

Sample Output:

Valid input:

Enter your age: 20  
You are 20 years old.

Invalid input (letters entered):

Enter your age: hello  
Invalid input! Please enter a valid number.  
Enter your age: 18  
You are 18 years old.

Clone this wiki locally