Java Program to Find Transpose of Matrix

Transpose of a grid is another network whose segments are the lines of unique framework and lines are the sections of the unique lattice.

Take underneath model for transpose of a grid of request 3×3.

Java Program to Find Transpose of Matrix

Underneath I have shared java program that will discover transpose of the lattice of any request.

On the off chance that you discover any trouble to see, at that point ask your inquiries in the remark segment.

Java Program to Find Transpose of Matrix

import java.util.Scanner;
 
class MatrixTranspose
{
 public static void main(String...s)
 {
  int m,n,i,j;  
 
  Scanner sc=new Scanner(System.in);
  System.out.println("Enter number of rows and columns:");
  m=sc.nextInt();
  n=sc.nextInt();
 
  int arr[][]=new int[m][n],trn[][]=new int[n][m];
 
  System.out.println("nEnter elements of matrix row wise:");
  
  for(i=0;i<m;++i)
   for(j=0;j<n;++j)
    arr[i][j]=sc.nextInt();
 
  for(i=0;i<m;++i)
   for(j=0;j<n;++j)
    trn[j][i]=arr[i][j];
 
 
  System.out.println("nMatrix after transpose:");
  for(i=0;i<n;++i)
  {
   for(j=0;j<m;++j)
    System.out.print(trn[i][j]+" ");
   System.out.print("n");
  }
       
 }
}  
Java Program to Find Transpose of Matrix

Leave a Comment

error: Alert: Content is protected!!