-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiply.java
More file actions
65 lines (45 loc) · 1.57 KB
/
Copy pathMultiply.java
File metadata and controls
65 lines (45 loc) · 1.57 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
55
56
57
58
59
60
61
62
63
64
65
package aljo;
import java.util.Scanner;
public class Multiply
{
public static void main(String[] args)
{
int i, j, k, rowF, rowS, colF, colS;
int first[][] = new int[10][10];
int second[][] = new int[10][10];
int product[][] = new int[10][10];
Scanner scanner = new Scanner(System.in);
System.out.println("Enter Rows and Cols of First Matrix");
rowF = scanner.nextInt();
colF = scanner.nextInt();
System.out.println("Enter Elements of First Matrix");
for (i = 0; i < rowF; i++) {
for (j = 0; j < colF; j++) {
first[i][j] = scanner.nextInt();
}
}
System.out.println("Enter Rows and Cols of Second Matrix");
rowS = scanner.nextInt();
colS = scanner.nextInt();
System.out.println("Enter Elements of Second Matrix");
for (i = 0; i < rowS; i++) {
for (j = 0; j < colS; j++) {
second[i][j] = scanner.nextInt();
}
}
for (i = 0; i < rowF; i++) {
for (j = 0; j < colF; j++) {
for (k = 0; k < colS; k++) {
product[i][j] += first[i][k] * second[k][j];
}
}
}
System.out.println("Product Matrix");
for (i = 0; i < rowF; i++) {
for (j = 0; j < colS; j++) {
System.out.print(product[i][j] + " ");
}
System.out.print("\n");
}
}
}