Declare Many Variables
You can declare multiple variables of the same type by listing them with commas in between.
Example
Instead of composing:
int x = 5;
int y = 6;
int z = 50;
System.out.println(x + y + z);
|
You can simply state:
int x = 5, y = 6, z = 50;
System.out.println(x + y + z);
|
One Value to Multiple Variables
In a single line, you can also assign a single value to multiple variables.
Example
int x, y, z;
x = y = z = 50;
System.out.println(x + y + z);
|