Skip to content

Instantly share code, notes, and snippets.

@bitcpf
Last active August 29, 2015 14:02
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 bitcpf/99fafb2eca0cce561a09 to your computer and use it in GitHub Desktop.
Save bitcpf/99fafb2eca0cce561a09 to your computer and use it in GitHub Desktop.
/*
Created by bitcpf
*/
public class Imagerotate {
public static int[][] Rotate(int[][] testimg){
for (int i = 0; i < testimg.length/2; i ++){
int first = i;
int last = testimg.length-1-i;
for (int j = first; j < last; j ++){
int offset = j-first;
int top = testimg[first][j];
// left to top
testimg[first][j] = testimg[last - offset][first];
// bottom to left
testimg[last-offset][first] = testimg[last][last-offset];
// right to bottom
testimg[last][last-offset] = testimg[first + offset][last];
// top to right
testimg[j][last] = top;
}
}
return testimg;
}
public static void Printimg(int[][] img){
for (int i = 0; i < img.length; i ++){
for (int j = 0; j < img[0].length; j ++){
System.out.print(img[i][j] + " ");
}
System.out.println("");
}
}
public static void main(String[] args){
int[][] testimg = new int[][] {{1,2,3},{4,5,6},{7,8,9}};
Printimg(testimg);
System.out.println("");
Printimg(Rotate(testimg));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment