- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Transpose a matrix in Java
A transpose of a matrix is the matrix flipped over its diagonal i.e. the row and column indices of the matrix are switched. An example of this is given as follows −
Matrix = 1 2 3 4 5 6 7 8 9 Transpose = 1 4 7 2 5 8 3 6 9
A program that demonstrates this is given as follows.
Example
public class Example { public static void main(String args[]) { int i, j; int row = 3; int col = 2; int arr[][] = {{2, 5}, {1, 8}, {6, 9} }; System.out.println("The original matrix is: "); for(i = 0; i < row; i++) { for(j = 0; j < col; j++) { System.out.print(arr[i][j] + " "); } System.out.print("
"); } System.out.println("The matrix transpose is: "); for(i = 0; i < col; i++) { for(j = 0; j < row; j++) { System.out.print(arr[j][i] + " "); } System.out.print("
"); } } }
Output
The original matrix is: 2 5 1 8 6 9 The matrix transpose is: 2 1 6 5 8 9
- Related Articles
- Java program to transpose a matrix.
- Java Program to Find Transpose of a Matrix
- Transpose a matrix in C#
- Transpose a matrix in Python?
- Java program to print the transpose of a matrix
- How to Transpose a Matrix using Python?
- Find the transpose of a matrix in Python Program
- How to Transpose a matrix in Single line in Python?
- C++ Program to Find Transpose of a Matrix
- Compute a matrix transpose with Einstein summation convention in Python
- C++ Program to Find Transpose of a Graph Matrix
- Python Program to find the transpose of a matrix
- Golang Program To Find The Transpose Of A Matrix
- How to calculate transpose of a matrix using C program?
- Program to find the transpose of given matrix in Python

Advertisements