Solution Review: Mirror a 2D Array
Understand how to create a mirror image of a 2D array by learning how to copy arrays correctly, traverse them in row-major order, and swap elements efficiently. This lesson breaks down the mirror function implementation step-by-step to help you confidently handle 2D array transformations in Java.
We'll cover the following...
Rubric criteria
Solution
Rubric-wise explanation
Point 1:
Look at line 23. We have the header of the mirror function. It takes an integer 2D array (int[][]) as a parameter and also returns an integer 2D array (int[][]).
Point 2:
In lines 28-34, we create a copy of the origArray (argument to the method) because we don’t want to change it.
❌ Note: We can’t do
array = origArray. Because this statement will makearraypoint toorigArray. So, any change inarraywill also be reflected outside the function.
Point 3:
Look at line 26. We have an outer for ...