Docy

Declare Many Variables

Estimated reading: 1 minute 841 views

Declare Many Variables

To declare more than one variable of the same type, you can use a comma-separated list:

Example

				
					int x = 5, y = 6, z = 50;
System.out.println(x + y + z);
				
			

One Value to Multiple Variables

You can also assign the same value to multiple variables in one line:

				
					int x, y, z;
x = y = z = 50;
System.out.println(x + y + z);
				
			

Leave a Comment

Share this Doc
CONTENTS