Question: Please help me complete. Thank you! import java.util.Arrays; public class RotateMatrix { private static void rotate(int[][] a) { // TODO int n = a.length; }
Please help me complete. Thank you!
import java.util.Arrays;
public class RotateMatrix {
private static void rotate(int[][] a) { // TODO
int n = a.length;
} public static void main(String[] args) { int [][]a; a = new int[][] { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 }, { 13, 14, 15, 16 } }; /* Expected: before: { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 }, { 13, 14, 15, 16 } after: { 13, 9, 5, 1}, { 14, 10, 6, 2}, { 15, 11, 7, 3}, { 16, 12, 8, 4} */ System.out.println("before: "); for (int[] row : a) System.out.println(Arrays.toString(row)); rotate(a); System.out.println(" after: "); for (int[] row : a) System.out.println(Arrays.toString(row)); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
