I am implementing a basic version of Conway's game of life but when applying the rules I come across a weird problem and I hope that someone here know whats going on.
It is just a basic if else if statement but values change depending if I compare them or not.
The value is printed before any comparison is carried out but having the if else if changes the result of the print.
with the if else if the results are
and without
Does anyone have any idea whats going on?
Cheers,
John
It is just a basic if else if statement but values change depending if I compare them or not.
Code:
public void rules() {
if(neighbours > 0) System.out.println(neighbours);
if(alive && (neighbours > 3 || neighbours < 2)) {
alive = false;
}
else if(!alive && neighbours == 3) {
alive = true;
}
}
The value is printed before any comparison is carried out but having the if else if changes the result of the print.
with the if else if the results are
Code:
1
1
1
2
1
1
2
1
1
1
and without
Code:
1
1
1
2
1
2
3
2
3
2
1
2
1
1
1
Does anyone have any idea whats going on?
Cheers,
John