forked from iRupam/NewtonSchoolInfinityJune21
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrixMultiplicstion.java
More file actions
54 lines (48 loc) · 1.52 KB
/
MatrixMultiplicstion.java
File metadata and controls
54 lines (48 loc) · 1.52 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
51
52
53
54
package InfinityJune21.TwoDArray;
public class MatrixMultiplicstion {
public static void main(String[] args) {
int n1 = 5, n2 = 3, n3 = 6;
int arr1[][] = new int[n1][n2];
int arr2[][] = new int[n2][n3];
int result[][] = new int[n1][n3];
int element = 1;
for(int i = 0; i < n1; i++) {
for(int j = 0; j < n2; j++) {
arr1[i][j] = element;
element++;
}
}
for(int i = 0; i < n1; i++) {
for(int j = 0; j < n2; j++) {
System.out.printf("%6d", arr1[i][j]);
}
System.out.println();
}
System.out.println();
for(int i = 0; i < n2; i++) {
for(int j = 0; j < n3; j++) {
arr2[i][j] = element;
element++;
}
}
for(int i = 0; i < n2; i++) {
for(int j = 0; j < n3; j++) {
System.out.printf("%6d", arr2[i][j]);
}
System.out.println();
}
for(int i = 0; i < n1; i++) {
for(int j = 0; j < n3; j++) {
for(int k = 0; k < n2; k++) {
result[i][j] = result[i][j] + (arr1[i][k] * arr2[k][j]);
}
}
}
for(int i = 0; i < n1; i++) {
for(int j = 0; j < n3; j++) {
System.out.printf("%6d", result[i][j]);
}
System.out.println();
}
}
}