How to set multiple int equal to one number? Java

I have a code int index, r, g, b;, and I want all of them to be equal to a certain number, I don’t want to write index = 0; r = 0;... and so on.

How to do this in java? index,r,g,b = 0;not working for me.

+4
source share
2 answers

use this line of code to initialize all variables at once

r = g = b = index = 0;

otherwise initialize when you declare:

int index=0, r=0, g=0, b=0;
+5
source

Initialize all values, then set the values.

int index, r, g, b;
index = r = g = b = 0;
+4
source

All Articles