/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/**
* How do you rotate a two dimensional array?
*
* Refer : http://stackoverflow.com/questions/42519/how-do-you-rotate-a-two-dimensional-array
*/
class Ideone {
public static void main
(String[] args
){ int[][] a = {
{1, 2, 3, 4 },
{5, 6, 7, 8 },
{9, 10, 11, 12},
{13, 14, 15, 16}
};
printMatrix("Before rotation :", a);
int m = a.length;
int n = a[0].length;
int[][] dest = new int[m][n];
for(int r=0; r<m; r++){
for(int c=0; c<n; c++){
dest[c][m-r-1] = a[r][c];
}
}
printMatrix("After rotation :", dest);
}
private static void printMatrix
(String str,
int[][] a
){
for(int i=0; i<a.length; i++){
for(int j=0; j<a[0].length; j++){
System.
out.
print(" "+a
[i
][j
]+ " "); }
}
}
}