二维数组行列互调

来源:互联网 发布:ue4 unity3d 编辑:程序博客网 时间:2024/06/11 23:28

将数组 1 2 3

             4 5 6

             7 8 9

转置为 1 4 7 

             2 5 8

             3 6 9

public class Eval{public static void main(String args[]){int[][] a = new int[][]{{ 1, 2, 3 },{ 4, 5, 6 },{ 7, 8, 9 } };System.out.println("转置前的数组:");for (int x[] : a)                    //!{for (int y : x)              //注意!{System.out.print(y + " ");}System.out.println();}System.out.println("转置后的数组:");for (int i = 0; i < a.length; i++){for (int j = 0; j < a.length; j++)System.out.print(a[j][i]+" ");System.out.println();}}}


0 0
原创粉丝点击