实现矩阵从外围到内依次输出

来源:互联网 发布:JS授权系统源码 编辑:程序博客网 时间:2024/05/29 13:07
package Day47;//实现输出矩阵的外围public class Test2 {public static void main(String[] args) {int[][] M={{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}};        int i=0;         for(int a=i;a<M.length;a++)//行数{for(int j=0;j<M[a].length-i;j++)//每一圈所有的列数{System.out.print(M[i][j]+" ");//if(j==M[a].length-1-i){for(int t=i+1;t<M.length;t++){System.out.print(M[t][j]+" ");}}} i++;System.out.println();}          }}输出结果:1 2 3 4 8 12 16 5 6 7 11 15 9 10 14 13