002-004-006

Input Validation: Age Range Check

Easy

Problem Description

Input Validation: Age Range Check

Learning Objective: Check if input value is within valid range

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

In an age input program, verify age is within valid range (0-120) and display result.
Read the integer with Scanner and use the condition age >= 0 && age <= 120 to determine if the age is valid or invalid.

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

Ready to Try Running Code?

Log in to access the code editor and execute your solutions for this problem.

Don't have an account?

Sign Up