Java: Declare Multiple Variables

Example

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);

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

Example

int x, y, z;
x = y = z = 50;
System.out.println(x + y + z);
posted @ 2022-11-24 02:16  小白冲冲  阅读(22)  评论(0)    收藏  举报