-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProject22.java
More file actions
57 lines (46 loc) · 1.58 KB
/
Project22.java
File metadata and controls
57 lines (46 loc) · 1.58 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
import java.util.Scanner;
public class Project22 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter te Row value for A");
int n1 = sc.nextInt();
System.out.println("Enter te Column value for A");
int m1 = sc.nextInt();
int[][] A = new int[n1][m1];
System.out.println("Enter first value for A :- ");
for (int i = 0; i < n1; i++) {
for (int j = 0; j < m1; j++) {
A[i][j] = sc.nextInt();
}
}
System.out.println("Enter te Row value for B");
int n2 = sc.nextInt();
System.out.println("Enter te Column value for B");
int m2 = sc.nextInt();
int[][] B = new int[n2][m2];
System.out.println("Enter first value for B :- ");
for (int i = 0; i < n2; i++) {
for (int j = 0; j < m2; j++) {
B[i][j] = sc.nextInt();
}
}
if (m1 != n2) {
System.out.println("------------------------Invalid input------------------------------");
return;
}
int[][] result = new int[n1][m2];
for (int i = 0; i < n1; i++) {
for (int j = 0; j < m2; j++) {
for (int k = 0; k < m1; k++) {
result[i][j] += A[i][k] * B[k][j];
}
}
}
for (int i = 0; i < n1; i++) {
for (int j = 0; j < m2; j++) {
System.out.print(result[i][j] + " ");
}
System.out.println();
}
}
}