Java Program to transpose the Matrix
Get a Matrix and perform transpose of Matrix
Program or Solution
//To Transpose The Matrix...
import java.util.*;
class Program
{
public static void main(String args[])
{
int m,n,i,j;
Scanner sc=new Scanner(System.in);
System.out.println("Enter The No.of Rows:");
m=sc.nextInt();
System.out.println("Enter The No.of Columns:");
n=sc.nextInt();
int a[][]=new int[m][n];
int c[][]=new int[m][n];
System.out.println("Enter The First Matrix:");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
a[i][j]=sc.nextInt();
}
}
System.out.println("The Transpose Matrix:");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
c[i][j]=a[i][j];
}
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
System.out.println(" "+c[j][i]);
}
}
}
}
Program Explanation
Comments
Related Programs
- Java Program to get and print the array elements
- Java Program to find the sum of array elements.
- Java Program to find the average of array Elements
- Java Program to Search an Element in an array
- Java Program to find Largest element in the array
- Java Program to find Smallest element in the array
- Java Program to print all the numbers which are less than given key element from a given array.
- Java Program to Sort the Elements in ascending order.
- Java Program to Sort the Elements in descending order.
- Addition of Matrix in Java
- Java Program to delete an Element from the Array
- Java Program to merge two Arrays
- Java Program to Multiply two Matrices
- Java Program to Reverse the Elements of Array
- Java Program to Reverse the First Half Elements of Array
- Java Program to Reverse the Second Half Elements of Array
- Java Program to find the Second Largest Number in the Array
- Java Program to find the Second Smallest Number in the Array
coming Soon
coming Soon