6

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

How do I do this in java? index,r,g,b = 0; doesn't work for me.

chrylis -cautiouslyoptimistic-
  • 75,269
  • 21
  • 115
  • 152
user2893243
  • 319
  • 2
  • 3
  • 10

2 Answers2

8

use this line of code for initializing all the variables at once

r = g = b = index = 0;

or else initialize when you declare like:

int index=0, r=0, g=0, b=0;
Aditya Vikas Devarapalli
  • 3,186
  • 2
  • 36
  • 54
5

Initialize all the values, then set the values.

int index, r, g, b;
index = r = g = b = 0;
hexacyanide
  • 88,222
  • 31
  • 159
  • 162