Last active
August 29, 2015 14:02
-
-
Save bitcpf/99fafb2eca0cce561a09 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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