019-001-001
Age Validation Program: Basic Exception Handling
Medium
Problem Description
A program that validates whether the user's age input is within a valid range (0-150 years old) and throws an exception if out of range. Learn input validation and exception handling through this exercise.
Test Cases
※ Output examples follow programming industry standards
Input:
25
Expected Output:
Valid
Input:
85
Expected Output:
Valid
Input:
0
Expected Output:
Valid
Input:
150
Expected Output:
Valid
Input:
-5
Expected Output:
Error: Age must be between 0 and 150
Input:
200
Expected Output:
Error: Age must be between 0 and 150
❌ Some tests failed
Your Solution
Current Mode:● My Code
99
1
2
3
4
5
6
7
8
9
10
›
⌄
⌄
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Write your code here
sc.close();
}
}
0 B / 5 MB
You have 10 free executions remaining
