1 /**
2 This example demonstrates variables and assignments.
3 */
4
5 public class VariableDemo
6 {
7 public static void main(String[] args)
8 {
9 int width = 10; // Declares width and initializes it with 10
10 System.out.print("width: ");
11 System.out.println(width);
12
13 width = 20; // Changes width to 20
14 System.out.print("width: ");
15 System.out.println(width);
16
17 int height = 20;
18 width = height + 10; // The right hand side can be an expression
19 System.out.print("width: ");
20 System.out.println(width);
21
22 width = width + 10; // The same variable can occur on both sides
23 System.out.print("width: ");
24 System.out.println(width);
25 }
26 }