Solution (source code)

= Solution

A <Java array> can hold references to row arrays. For example,
``
double[][] grid = new double[rows][columns];
grid[2][3] = 4.5;
``
allocates the outer array and all equal-length rows, with numeric entries initially zero. A ragged alternative is
``
double[][] grid = new double[rows][];
for (int r = 0; r < rows; r++)
    grid[r] = new double[r + 1];
``
The second form initially has null row references, so each row must be allocated before access. Rows need not have equal lengths, and a two-dimensional array of objects initially contains null object references rather than constructed cell objects. \b[Java represents a two-dimensional array as an array of arrays.]