Page 495 - AP Computer Science A, 7th edition
P. 495
What does it do? How does it transform the matrix below?
234 567 890 111
Solution: The algorithm reflects the matrix from top to bottom across a horizontal mirror placed at its center.
height = 4, numCols = 3 col takesonvalues 0, 1, and 2 row takesonvalues 0 and 1
Here are the replacements that are made:
col = 0, row = 0: mat[3][0] = mat[0][0] row = 1: mat[2][0] = mat[1][0]
col = 1, row = 0: mat[3][1] = mat[0][1] row = 1: mat[2][1] = mat[1][1]
col = 2, row = 0: mat[3][2] = mat[0][2] row = 1: mat[2][2] = mat[1][2]
This transforms the matrix into
234 567 567 234
Note that a for-each loop was not used in the traversal, because elements in the matrix are being replaced.
BASE 2, BASE 8, BASE 16
Binary (base 2) and hexadecimal (base 16) numbers are discussed