Java二维数组螺旋输出

即顺时针或逆时针打印二维数组:

public class TestDemo {
    public static void main(String[] args){
        int[][] arr = {{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}};
        int circle = arr[0].length/2;
        int count = 0;
        while(count count;colum--){
                System.out.print(arr[arr.length-1-count][colum]+" ");
            }
            //左
            for(int row = arr.length-1-1-count+1;row >= count+1.;row--){
                System.out.print(arr[row][count]+" ");
            }
            count++;
        }

    }
}

你可能感兴趣的:(日常总结)