For in-place rotation, you must swap four cells at a time using a temporary variable. This is more efficient but harder to debug.
int[][] matrix = 1, 2, 3, 4, 5, 6, 7, 8, 9 ;
array[row].length gives you the number of in that specific row. 3. Conditional Logic (If-Statements)
public static void swapColumns(int[][] arr, int colA, int colB) for (int row = 0; row < arr.length; row++) int temp = arr[row][colA]; arr[row][colA] = arr[row][colB]; arr[row][colB] = temp;
swapRows(test, 0, 2); System.out.println("\nAfter swapping row 0 and 2:"); print2D(test);
For in-place rotation, you must swap four cells at a time using a temporary variable. This is more efficient but harder to debug.
int[][] matrix = 1, 2, 3, 4, 5, 6, 7, 8, 9 ; Codehs 8.1.5 Manipulating 2d Arrays
array[row].length gives you the number of in that specific row. 3. Conditional Logic (If-Statements) For in-place rotation, you must swap four cells
public static void swapColumns(int[][] arr, int colA, int colB) for (int row = 0; row < arr.length; row++) int temp = arr[row][colA]; arr[row][colA] = arr[row][colB]; arr[row][colB] = temp; For in-place rotation
swapRows(test, 0, 2); System.out.println("\nAfter swapping row 0 and 2:"); print2D(test);