Age Validator (Exception)
PHP
Medium
4 views
Problem Description
If age is between 0 and 120, print OK. Otherwise print INVALID_AGE.
Input Format
One integer age.
Output Format
OK or INVALID_AGE.
Official Solution
<?php
$inputText=trim(stream_get_contents(STDIN));
if($inputText==='') exit;
$age=intval($inputText);
try{
if($age<0 || $age>120) throw new Exception('bad');
echo 'OK';
}catch(Exception $e){
echo 'INVALID_AGE';
}
?>
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!