Transpose of a Matrix in Java (ISC Program)
To learn about how to take input in java watch the given video. https://youtu.be/QZKcULOC4lg
A matrix is a collection of numbers arranged into a fixed number of rows and columns. It is called a double dimensional array also.
The transpose of a matrix is a matrix where the row becomes columns and column becomes row.
Write a program to accept a double dimensional array (matrix) and print transpose of a matrix.
To learn about how to take input in java watch the given video.
https://youtu.be/QZKcULOC4lg
import java.io.*;
public class Transarray
{
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int arr[][];
int m,n;
Transarray()
{
m=0;
n=0;
}
Transarray(int mm,int nn)
{
m=mm;
n=nn;
arr=new int[mm][nn];
}
void fillarray()throws IOException
{
System.out.println("enter the elements of the array");
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
arr[i][j]=Integer.parseInt(br.readLine());
}
}
}
void transpose(Transarray a)
{
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
this.arr[i][j]=a.arr[j][i];
}
}
}
void display()
{
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
System.out.print(arr[i][j] + "\t");
}
System.out.println();
}
}
public static void main() throws IOException
{
System.out.println("Enter the order(size) of the array");
int r=Integer.parseInt(br.readLine());
int c=r;
Transarray obj=new Transarray(r,c);
Transarray obj1=new Transarray(r,c);
obj.fillarray();
obj.display();
obj1.transpose(obj);
System.out.println("The transpose of the array is:");
obj1.display();
}
}Enter the order(size) of the array
3
Enter the elements of the array
1
2
3
4
5
6
7
8
9
1 2 3
4 5 6
7 8 9
The transpose of the array is:
1 4 7
2 5 8
3 6 9
To learn more about array click the given link
Array in JAVA
Related Posts
Continue learning with these related articles

Logic Gates for ISC Class 11: Truth Tables, Universal Gates, Half and Full Adder
ISC Class 11 Computer Science notes on logic gates: AND, OR, NOT, NAND, NOR, XOR and XNOR with truth tables, why NAND and NOR are universal gates, and half adder and full adder circuits with their Boolean expressions.
Decimal to Binary Conversion in Java: 3 Programs with Examples
How to convert a decimal number to binary on paper and in Java: three programs (String, place value and Integer.toBinaryString), binary to decimal, a dry run and common mistakes.

ISC Class 11 Computer Science Sample Paper 2026-27 with Solutions
A full 70-mark ISC Class 11 Computer Science sample paper for the 2026-27 annual exam: MCQs, number systems, propositional logic, logic gates, Java classes, arrays, strings, searching and sorting, and computing ethics, with complete worked solutions.