Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Trans
- {
- public static double[][] transposeMatrix(double [][] m)
- {
- double[][] temp = new double[m[0].length][m.length];
- for (int i = 0; i < m.length; i++)
- for (int j = 0; j < m[0].length; j++)
- temp[j][i] = m[i][j];
- return temp;
- }
- public static void main(String args[])
- {
- // initialize the variable
- Scanner s = new Scanner(System.in);
- System.out.println("enter row and column");
- int row = s.nextInt();
- int column = s.nextInt();
- double[][] a = new double[row][column];
- for (int i = 0; i < row; i++)
- {
- for (int j = 0; j < column; j++)
- {
- double b = s.nextDouble();
- a[i][j]=b;
- }
- System.out.println();
- }
- double[][] c = new double[row][column];
- c = transposeMatrix(a);
- // operation for transpose
- System.out.println("Transpose matrix:");
- // After Transpose the matrix print the result
- for (int i = 0; i < column; i++)
- {
- for (int j = 0; j < row; j++)
- {
- System.out.print(c[i][j]+" ");
- }
- System.out.println();
- }
- }
- }
Add Comment
Please, Sign In to add comment