思路:
沿着斜线打印即可。
public void print_rotate_matrix(int[] matrix , int n){ if(n<0||matrix==null||matrix.length==0) return; //打印右上角 for(int i = n-1; i>=0 ; i--){ int j = i; while((j+1)%n!=0) { System.out.print(matrix[j]+" "); j+=(n+1); } System.out.println(matrix[j]); } //打印左下角 for(int i = n; i<= matrix.length - n ; i+=n){ int j = i; while(j < matrix.length - n) { System.out.print(matrix[j]+" "); j+=(n+1); } System.out.println(matrix[j]); } }
原文地址:http://blog.csdn.net/cow__sky/article/details/39226677