002-004-001

Input Validation: Age Range Check

Easy

Problem Description

Input Validation: Age Range Check

In this problem, you will create a program that reads an age (integer) from standard input, uses an if statement to check whether it falls within the valid range of 0–120, and displays the result to standard output.

Learning Objective: Check if input value is within valid range

In an age input program, verify age is within valid range (0-120) and display result.
Checking input values improves program reliability.

Input

Line 1: Age (integer)

Output

If age is within 0-120 range:

Valid age
Age: [age] years old
```java

If out of range:
```java
Invalid age

Test Cases

※ Output examples follow programming industry standards

Normal case
Input:
25
Expected Output:
Valid age
Age: 25 years old
Normal case
Input:
0
Expected Output:
Valid age
Age: 0 years old

Your Solution

Current Mode: My Code
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