Skip to content
Open
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
31 changes: 31 additions & 0 deletions Transpose
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
public class Transpose {

public static void main(String[] args) {
int row = 2, column = 3;
int[][] matrix = { {2, 3, 4}, {5, 6, 4} };

// Display current matrix
display(matrix);

// Transpose the matrix
int[][] transpose = new int[column][row];
for(int i = 0; i < row; i++) {
for (int j = 0; j < column; j++) {
transpose[j][i] = matrix[i][j];
}
}

// Display transposed matrix
display(transpose);
}

public static void display(int[][] matrix) {
System.out.println("The matrix is: ");
for(int[] row : matrix) {
for (int column : row) {
System.out.print(column + " ");
}
System.out.println();
}
}
}