001-006-016
Variable Scope in Blocks
Easy
Problem Description
variable Scope in Blocks
In this problem, you will create a program that declares a variable count at the beginning of the main method, increments it inside a for loop five times, and displays its final value to standard output.
Learning Objective: Understand the relationship between variable declaration position and scope
Overview
Declare a variable inside a method and verify where it can be accessed. A variable declared at the beginning of a method can be used throughout that method.
Specifications
- Initialize variable
countwith 0 at the beginning of main method - Use a for loop to iterate 5 times, incrementing
counteach time - Output the final value of
countafter the loop
Output Format
Count: 5
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