001-003-009

Local Variable Scope

Easy

Problem Description

Local variable Scope

In this problem, you will create a program that uses an if block inside the main method to declare variables (outer and inner) at different scopes, verify the scope differences between inside and outside the block, and displays the result to standard output.

Learning Objective: Understand the scope of local variables declared within methods

Overview

Declare variables in different blocks within a method and verify scope differences.

Specifications

  • Initialize integer variable outer with 10 in main method
  • Initialize integer variable inner with 20 inside if block
  • Output both variables inside the if block
  • Output only outer outside the if block

Output Format

Inside block: outer=10, inner=20
Outside block: outer=10

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