Hi,
I am trying to figure out how compare two values in a boolean array. For example:
if [i] = true, compare [i+1] and [i-1]... then, if one is true, and the other is false, [i] = true.
Here's a snippet of what I am working on:
public static void theLivingDead(boolean[] villagers) {
for (int i=0; i<villagers.length; i++) {
if (villagers[i] == true) {
if (villagers[i++] == true && villagers[i--] == false) {
villagers[i] = false;
}
else {
villagers[i] = true;
}
}
else {
if (villagers[i++] == true && villagers[i--] == false) {
villagers[i] = true;
}
else {
villagers[i] = false;
}
}
}
}
You can probably see what I am trying to do by reading the code, however, I am clearly missing something.