Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions Java/program-3/program.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,63 @@
//Java Program to Find Transpose of a Matrix//






import java.util.Arrays;

public class Matrix {

// main method
public static void main(String[] args) {

// declare and initialize a matrix
int a[][] = { { 1, 2 }, { 8, 9 } };

// find row and column size
int row = a.length;
int column = a[0].length;

// declare new matrix to store result
int transpose[][] = new int[row][column];

// Transpose of matrix
transpose = transposeMatrix(a);

// display all matrices
System.out.println("A = " + Arrays.deepToString(a));
System.out.println("Transpose = " +
Arrays.deepToString(transpose));
}

// method to calculate the transpose of a matrix
public static int[][] transposeMatrix(int[][] a) {

// calculate row and column size
int row = a.length;
int column = a[0].length;

// declare a matrix to store resultant
int temp[][] = new int[row][column];

// calculate transpose of matrix
// outer loop for row
for (int i = 0; i < row; i++) {
// inner loop for column
for (int j = 0; j < column; j++) {
// formula
temp[i][j] = a[j][i];
}
}

// return resultant matrix
return temp;
}

}


import java.io.*;
import java.util.*;
class Prg{
Expand Down