009-001-005
private Modifier: Protected Counter
Easy
Problem Description
private Modifier: Protected Counter
In this problem, you will create a program that protects a counter value with a private field, increments it using an increment method, and displays the initial and incremented values to standard output.
Learning Objective: Protect object state with private fields
Create class managing counter value. Protect count value with private field to prevent direct external modification, manipulate with increment method and getter.
Input
Line 1: Increment times (integer)
Output
Initial: 0
After increment: [times]
Examples
Example 1: Increment 3 times
Input:
3
Output:
Initial: 0
After increment: 3
Example 2: Increment 5 times
Input:
5
Output:
Initial: 0
After increment: 5
Example 3: 0 times (boundary)
Input:
0
Output:
Initial: 0
After increment: 0
Test Cases
※ Output examples follow programming industry standards
Input:
3
Expected Output:
Initial: 0 After increment: 3
Input:
5
Expected Output:
Initial: 0 After increment: 5
Input:
0
Expected Output:
Initial: 0 After increment: 0
Input:
100
Expected Output:
Initial: 0 After increment: 100
❌ Some tests failed
Your Solution
Current Mode:● My Code
Counter.java🔒
Solution.java🔒
2/6 ファイル96B
⚠️警告
- No main method found
9
1
2
3
4
›
⌄
import java.util.Scanner;
class Counter {
}
0 B / 5 MB
You have 9 free executions remaining
