I need to write a simple program as an assignment on the terms of the game "Life." All field values are stored in my array of Boolean values. I have written a method that checks cells around a cell under different conditions and increases the counter +1 if it finds a “live” (true) cell. In addition to location conditions, there is naturally a condition that takes a value from an array. And if this value is false, then execution for some reason stops and does not go any further. In the example below, "1" will not be displayed in the console and the program will not terminate (it will hang for something) if fieldLikeBooArray [length - width + point] is false:
public int checkPointsAround(int point, int width, boolean[] fieldLikeBooArray){ int alivePointsAround = 0; int length = fieldLikeBooArray.length; int count = 0; if (count == 0 && point - width < 0 && fieldLikeBooArray[length - width + point]) alivePointsAround++; //верхний сосед первая строка else if (count == 0 && fieldLikeBooArray[point - width]) alivePointsAround++; //верхний сосед остальные строки System.out.println(1); return alivePointsAround;} Why? Moreover, if you break it into two separate conditions (which seems very crooked), it works. Example:
if (point - width < 0) { if (fieldLikeBooArray[length - width + point]) alivePointsAround++; //верхний сосед первая строка } else if (fieldLikeBooArray[point - width]) alivePointsAround++; System.out.println(1); Perhaps the question is extremely simple, but for the second day I can not understand where I was wrong. Help! If necessary, I can lay out all the code.