Consider the next program

  1. A = 3 * 5
  2. B = 5 * 5
  3. Answer = B - A

The third line of the program is using the values of the variables A and B. The following diagram demonstrates this.

The first line assigns the value 15 into the variable A. The second line assigns the value 25 into the variable B. Finally the third line gets the value 25 from B and subtracts that value by 15; which is retrieved from the variable A.

A variable is stored in memory. That means that a small block of memory is created to store that value in. It can then be used time and time again as the programmer completes their tasks.

next creating a variable in java >>

 
Basics
Menu
Search