forked from MohmedIkram/Hacktoberfest2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Transpose_matrix.java
58 lines (58 loc) · 1.2 KB
/
Transpose_matrix.java
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
51
52
53
54
55
56
57
58
import java.util.*;
class trans
{
int ar[][],m;
trans(int a)
{
m=a;
ar=new int [m][m];
}
void input()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter elements of array");
for (int i=0;i<m;i++)
{
for (int j=0;j<m;j++)
{
ar[i][j]=sc.nextInt();
}
System.out.println();
}
}
void check(trans A)
{
boolean flag=true;
for (int i=0;i<m;i++)
{
for (int j=0;j<m;j++)
{
if(ar[i][j]!=A.ar[i][j])
flag=false;
}
}
if(flag==false)
System.out.println("NOT TRANSPOSE MATRIX");
else
System.out.println("TRANSPOSE MATRIX");
}
void transpose(trans k)
{
for (int i=0;i<m;i++)
{
for (int j=0;j<m;j++)
{
ar[i][j]=k.ar[j][i];
}
}
}
public static void main(int s)
{
trans ob1=new trans(s);
ob1.input();
trans ob2=new trans(s);
ob2.input();
ob1.transpose(ob1);
ob2.check(ob1);
}
}