Skip to content

Instantly share code, notes, and snippets.

@jyhjuzi
Created June 19, 2014 00:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jyhjuzi/0fb0c4ae211667a73cc9 to your computer and use it in GitHub Desktop.
Save jyhjuzi/0fb0c4ae211667a73cc9 to your computer and use it in GitHub Desktop.
public class Q1_6{
public static void main(String args[]){
int a[][] = {
{1, 2, 3, 4},
{5, 6, 7, 8},
{9, 10, 11, 12},
{13, 14, 15, 16}};
rotate(a);
for(int[] x :a){
for(int integer :x)
System.out.print(integer+" ");
System.out.println(" ");
}
}
static void rotate(int[][] matrix){
int size = matrix.length;
for(int i = 0; i <= size/2; i++){
for(int j =i; j < size-i-1; j++){
int temp = matrix[i][j];
matrix[i][j] = matrix[size-1-j][i];
matrix[size-1-j][i] = matrix[size-1-i][size-1-j];
matrix[size-1-i][size-1-j] = matrix[j][size-1-i];
matrix[j][size-1-i] = temp;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment