source file name: TransMatrix,java

class TransMatrix

{

public static void main(String as[])

{

int A[][]={{10,5,25},{3,-4,10},{1,2,3},{11,12,13}};

int B[][]=new int[3][4];

System.out.println("Matrix A");

for(int i=0;i<4;i++)

{

for(int j=0;j<3;j++)

{

System.out.print(A[i][j]+" ");

}

System.out.println();

}

for(int i=0;i<3;i++)

{

for(int j=0;j<4;j++)

{

B[i][j]=A[j][i];

}

}

System.out.println("Transpose Matrix A");

for(int i=0;i<3;i++)

{

for(int j=0;j<4;j++)

{

System.out.print(B[i][j]+" ");

}

System.out.println();

}

}

}

output:

D:\JavaPrograms\ArrayPrograms>javac TransMatrix.java

D:\JavaPrograms\ArrayPrograms>java TransMatrix
Matrix A
10 5 25
3 -4 10
1 2 3
11 12 13
Transpose Matrix A
10 3 1 11
5 -4 2 12
25 10 3 13