顺时针打印矩阵
public class Exercise {
public static void main(String[] args) {
// TODO Auto-generated method stub
int matrix[][]=new int [][]{{1,2,9,3,4},{2,7,3,4,5},{3,5,4,5,6},{4,5,4,6,7},{5,6,3,7,8}};
System.out.println("矩阵为:");
for(int[] ma:matrix){
for(int m:ma){
System.out.print(m+" ");
}
System.out.println();
}
System.out.println("顺时针打印矩阵:");
int size=matrix.length/2;
int s=size;
while(size>=0){
int a=0+(s-size),b=0+(s-size);
while(b<matrix[0].length-(s-size)){
System.out.print(matrix[a][b]+" ");
b++;
}
b--;
a++;
while(a<matrix.length-(s-size)){
System.out.print(matrix[a][b]+" ");
a++;
}
b--;
a--;
while(b>=0+(s-size)){
System.out.print(matrix[a][b]+" ");
b--;
}
b++;
a--;
while(a>0+(s-size)){
System.out.print(matrix[a][b]+" ");
a--;
}
size--;
}
}
}