Page 1028 - AP Computer Science A, 7th edition
P. 1028
28. (D) Segment II is the straightforward solution. Segment I is correct because it initializes all slots of the matrix to 0, a perfect square. (By default, all arrays of int or double are initialized to 0.) Segment III fails because r is undefined in the condition c < mat[r].length. In order to do a column-by- column traversal, you need to get the number of columns in each row. The outer for loop could be
for (int c = 0; c < mat[0].length; c++)
Now segment III works. Note that since the array is rectangular, you can use any index k in the conditional c < mat[k].length, provided that k satisfies the condition 0 ≤ k < mat.length (the number of rows).