-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransposematrix.java
More file actions
35 lines (35 loc) · 933 Bytes
/
Copy pathTransposematrix.java
File metadata and controls
35 lines (35 loc) · 933 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.util.Scanner;
public class Transposematrix {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int rows,cols;
System.out.println("enter rows ");
rows=s.nextInt();
System.out.println("enter columns ");
cols=s.nextInt();
int ar[][]=new int[rows][cols];
for(int i=0;i<rows;i++)
{
for(int j=0;j<cols;j++)
{
ar[i][j]=s.nextInt();
}
}
int ar2[][]=new int[rows][cols];
for(int i=0;i<rows;i++)
{
for(int j=0;j<cols;j++)
{
ar2[i][j]=ar[j][i];
}
}
for(int i=0;i<rows;i++)
{
for(int j=0;j<cols;j++)
{
System.out.print(ar2[i][j]);
}
System.out.println();
}
}
}