002-004-009
Age Input Validation Program
Medium
Problem Description
Age Input Validation Program
In this problem, you will create a program that receives an integer (age) from standard input, validates whether it falls within the range of 0 to 120, and displays the result to standard output.
Learning Objective: Understand how to receive user input, convert to appropriate type, and validate
Overview
Create a program that receives age as input from the user and validates whether the value is valid. Learn the basics of input value range checking.
Specifications
- Receive one integer (age) from standard input
- If the input value is between 0 and 120 inclusive, output
Valid age: {input value} - Otherwise, output
Invalid age
Input Format
25
Output Format
If input is valid:
Valid age: 25
If input is invalid:
Invalid age
Hints
- Use
Scannerto receive integer input - Use
ifstatement to check the range
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