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

Ready to Try Running Code?

Log in to access the code editor and execute your solutions for this problem.

Don't have an account?

Sign Up