Java Variables
If you want to declare many variables of the same type, you can use a list separated by commas:
Instead of writing:
int x = 5;
int y = 6;
int z = 50;
System.out.println(x + y + z);
You can simply write:
int x = 5, y = 6, z = 50;
System.out.println(x + y + z);
Additionally, you can set the same value for several variables in a single line:
int x, y, z;
x = y = z = 50;
System.out.println(x + y + z);
CodingAsk.com is designed for learning and practice. Examples may be made simpler to aid understanding. Tutorials, references, and examples are regularly checked for mistakes, but we cannot guarantee complete accuracy. By using CodingAsk.com, you agree to our terms of use, cookie, and privacy policy.
Copyright 2010-2024 by Refsnes Data. All Rights Reserved.