//将一个三行四列的数组进行转置输出(转置就是行列互换,行变列,列变行)。
作者:互联网
package Experiment.Java.test10;
public class test01 {
public static void main(String[] args) {
int [][] array ={{1,2,5,9},{2,3,8,5},{3,5,6,4}};
for (int i = 0; i <array.length ; i++) { //i=0是因为下标从0开始----外层循环
for (int j = 0; j <array[i].length ; j++) {//内层循环,循环数组里的每个元素
System.out.print(array[i][j]+"\t");
}
System.out.println(); //每个数组遍历完就换行
}
System.out.println("==============");
for (int i = 0; i <=array.length ; i++) {
for (int j = 0; j <array.length ; j++) {
System.out.print(array[j][i]+"\t");
}
System.out.println();
}
}
}
标签:行变列,四列,转置,System,int,println,array,out 来源: https://blog.csdn.net/PPXhinata/article/details/116136363