Using an array,
boolean bs = new boolean[10];
lightUp(bs, 6); // only bs[6] will be true after this
lightUp(bs, 0); // only bs[0] will be true after this
With the lightUp function defined as:
/**
* modifies the passed-in array to make sure only
* the selected index is set to true
*/
void lightUp(boolean[] bs, int index) {
for (int i=0; i<bs.length; i++) bs[i] = false;
bs[index] = true;
}
2
solved In Java, if one boolean true then all others become false [closed]