Page 367 - AP Computer Science A, 7th edition
P. 367

return mat; }
To call this method:
//prompt for number of rows and columns
int rows = IO.readInt(); //read user input int cols = IO.readInt(); //read user input int[][] mat = getMatrix(rows, cols);
NOTE
You cannot use a for-each loop in getMatrix because elements in mat are being replaced. (Their current value is the initialized value of 0. The new value is the input value from the keyboard.)
There is further discussion of arrays and matrices, plus additional questions, in Chapter 9 (The AP Computer Science Labs).




























































































   365   366   367   368   369