013-003-002
Field Initialization: Counter
Easy
Problem Description
Field Initialization: Counter
In this problem, you will create a program that implements a Counter class with both a field initialized at declaration time (default value: 0) and a field initialized via constructor using a given starting value, and displays the result to standard output.
Learning Objective: Understand when and how fields are initialized
Create a Counter class and observe the difference between field declaration initialization and constructor initialization.
Input
Line 1: Starting value (integer)
Output
Default count: 0
Custom count: [starting value]
Test Cases
※ Output examples follow programming industry standards
Normal case
Input:
100
Expected Output:
Default count: 0 Custom count: 100
Normal case
Input:
50
Expected Output:
Default count: 0 Custom count: 50
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 10 free executions remaining
