# Write a program that reads a 5 x 5 two dimensional array of integers There are four squares to consider. I will only cover a part of the programming for this example. In the program, the life grid is shown as a grid of squares in which dead squares are black and living squares are white.

The rules apply to each individual cell, so again we can use nested for loops to work through all the cells on the board, but this time the processing is more complicated.

Each row is in fact a value of type int[]. In fact, it's even possible for a row to be null. Consider the cell in row r and column c.

As an example, consider a symmetric matrix. We have to look through all the positions in the array and find the pieces that belong to the current player. The rules are applied to every cell in the grid.

## Write a program that reads a 5 x 5 two dimensional array of integers

In the program, the life grid is shown as a grid of squares in which dead squares are black and living squares are white. Other pieces that can legally be moved are surrounded by a cyan-colored border. The contents of the grid at each time step are completely determined by the contents at the previous time step, according to simple rules: Each cell in the grid looks at its eight neighbors horizontal, vertical, and diagonal and counts how many of its neighbors are alive. When a player moves a piece from one square to another, the values of two elements in the array are changed. Consider the 3-by-4 array A defined above. I use variables to represent the positions above, below, left, and right of a given cell. Java does not actually have two-dimensional arrays. It could, for example, be passed to a subroutine that asks for a parameter of type int[]. This method is a function that returns an array of type CheckersMove[]. It took a good deal of design work to decide what classes and objects would be used, what methods should be written, and what algorithms the methods should use.

The old array will be garbage collected. The elements in a 2D array of type int[][] are variables of type int[]. After that, the game "plays itself.

Rated 6/10 based on 84 review