创建一个二维数组,实现该数组的行列转置,输出

来源:互联网 发布:自动脱壳软件 编辑:程序博客网 时间:2024/06/16 19:10
package tag;/* * 创建一个二维数组(4*3),实现该数组的行列转置,输出。 * 运行结果: * 转置前:1 2 3 *             4 5 6 *              7 8 9 *              10 11 12 *  */public class Test5 {public static void main(String[] args) {int[][] a = {{1,2,3},{4,5,6},{7,8,9},{10,11,12}};for (int i = 0; i < 3; i++) {for (int j = 0; j < 4; j++) {System.out.print(a[j][i]+" ");}System.out.println();}}}