002-004-009

Age Input Validation Program

Medium

Problem Description

Age Input Validation Program

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

  1. Receive one integer (age) from standard input
  2. If the input value is between 0 and 120 inclusive, output Valid age: {input value}
  3. Otherwise, output Invalid age

Input Format

25

Output Format

If input is valid:

Valid age: 25

If input is invalid:

Invalid age

Hints

  • Use Scanner to receive integer input
  • Use if statement 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?