代码:
public class Test { public static void main(String args[]) { int a[][]={{1,4,6,10},{3,5,8,14},{6,7,9,21}}; int b[][]=new int[4][3]; System.out.println("矩阵转置前为 "); for(int i=0;i<3;i++) { for(int j=0;j<4;j++) { b[j][i]=a[i][j];//进行转置 System.out.print(a[i][j]+" "); } System.out.println(); } System.out.println("矩阵转置后为 "); for(int i=0;i<4;i++) { for(int j=0;j<3;j++) { System.out.print(b[i][j]+" "); } System.out.println(); } } }