From 050b4691ab5d3fa966b6e068da9cce74ada63ab4 Mon Sep 17 00:00:00 2001 From: code5am <70967850+code5am@users.noreply.github.com> Date: Tue, 25 Oct 2022 21:29:28 +0530 Subject: [PATCH] Create Transpose --- Transpose | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Transpose diff --git a/Transpose b/Transpose new file mode 100644 index 0000000..d86ccf1 --- /dev/null +++ b/Transpose @@ -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(); + } + } +}