005-001-002
If Statement: Entrance Check
Easy
Problem Description
if statement: Entrance Check
Learning Objective: Perform conditional judgment with if statement
In this problem, you will create a program that reads an age (integer) from standard input, uses an if-else statement to determine whether the person is 18 or older, and displays the entrance eligibility message to standard output.
Use Scanner to read the age as an integer, then implement branching with an if-else statement. For ages 18 and above, print "You can enter"; for ages below 18, print "You cannot enter" — each preceded by the age value.
Input
Line 1: Age (integer)
Output
For 18+:
Your age: [age] years old
You can enter
```java
For under 18:
```java
Your age: [age] years old
You cannot enter
Test Cases
※ Output examples follow programming industry standards
Normal case
Input:
20
Expected Output:
Your age: 20 years old You can enter
Normal case
Input:
15
Expected Output:
Your age: 15 years old You cannot enter
Your Solution
Current Mode:● My Code
99
1
2
3
4
5
6
7
8
9
10
›
⌄
⌄
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
