-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTranspose_2D.java
More file actions
50 lines (47 loc) · 1.25 KB
/
Transpose_2D.java
File metadata and controls
50 lines (47 loc) · 1.25 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import java.util.*;
public class Transpose_2D
{
public static void main(String[]args)
{
Scanner as = new Scanner(System.in);
int[][]a;
int i,j,k;
System.out.println("\tThe Transposed Array Printing Program\n");
System.out.println("Enter the Size of The Square Matrix:");
int n=as.nextInt();
a=new int[n][n];
System.out.println("Enter the Numbers in the Array:");
for(i=0;i<n;i++)
{
System.out.println("Row:"+(i+1));
for(j=0;j<n;j++)
a[i][j]=as.nextInt();
}
System.out.println("The Array:");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
System.out.print(a[i][j]+" ");
System.out.println();
}
System.out.println("\nThe Transposed Array:");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(i>j)
{
k=a[i][j];
a[i][j]=a[j][i];
a[j][i]=k;
}
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
System.out.print(a[i][j]+" ");
System.out.println();
}
}
}