-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransposeMatrix.java
More file actions
46 lines (40 loc) · 853 Bytes
/
transposeMatrix.java
File metadata and controls
46 lines (40 loc) · 853 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
36
37
38
39
40
41
42
43
44
45
46
import java.io.*;
import java.util.Scanner;
import java.util.StringTokenizer;
class Transpose
{
public static void main(String args[]) throws IOException
{
System.out.print("Enter rows, columns: ");
Scanner sc = new Scanner(System.in);
int rows = sc.nextInt();
int columns = sc.nextInt();
System.out.println("Enter elements of matrix: ");
int arr[][] = new int[rows][columns];
for (int i=0;i<rows;i++)
{
for (int j=0;j<columns;j++)
{
arr[i][j] = sc.nextInt();
}
}
System.out.println("Your array is: ");
for (int i=0;i<rows;i++)
{
for (int j=0;j<columns;j++)
{
System.out.print(arr[i][j] + " ");
}
System.out.print("\n");
}
System.out.println("Your transpose array is: ");
for (int i=0;i<columns;i++)
{
for (int j=0;j<rows;j++)
{
System.out.print(arr[j][i] + " ");
}
System.out.print("\n");
}
}
}