COMP2243 - Programming and Problem Solving

Syllabus Software Installation Assignments Tests
Lectures and Labs
**Back to Full Menu**

Methods RightTriangle.java RightTriangleWithLoop.java Geometry.java PayrollWithMethod.java PayrollWithMethodLoop.java Palindrome.java GlobalAndLocal.java Overloading.java Overloading2.java MathMethods.java and MathProgram.java CaesarCipher.java



GlobalAndLocal Program


Description

This program demonstrates the difference between global and local variables.

Associated Concepts:

Variable scope: global and local variables

Algorithm:

Declare a global variable x and initialize it to certain value

main method:

Declare a local variable x and initialize it to another value

Change the value of the local variable x

Print both the local and global variables x

Call three methods which are supposed to modify the value of the global variable x

Print both the local and global variables x

Write three method definitions

Modify the value of the global variable x

Source Code



Sample Run



Video