-
Notifications
You must be signed in to change notification settings - Fork 0
/
Trr.java
67 lines (67 loc) · 1.62 KB
/
Trr.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
59
60
61
62
63
64
65
66
67
//Q18
import java.util.*;
public class Trr
{
int arr[][];
Trr(){
arr= new int[3][3];
}
void input(){
System.out.println("Enter matrix");
Scanner sc= new Scanner(System.in);
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
arr[i][j]=sc.nextInt();
}
}
}
Trr transpose(){
Trr obj=new Trr();
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
obj.arr[i][j]=arr[j][i];
}
}
return obj;
}
Trr product(Trr M){
Trr obj= new Trr();
Trr t= transpose();
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
for(int k = 0; k < 3; k++){
obj.arr[i][j]+= arr[i][k] * t.arr[k][j];
}
}
}
return obj;
}
void display(){
Trr obj = transpose();
Trr m= product(obj);
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
System.out.print(arr[i][j]+" ");
}
System.out.println();
}
System.out.println("X");
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
System.out.print(obj.arr[i][j]+" ");
}
System.out.println();
}
System.out.println("=");
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
System.out.print(m.arr[i][j]+" ");
}
System.out.println();
}
}
void main(){
input();
display();
}
}