-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmulti_array.java
44 lines (42 loc) · 1.45 KB
/
multi_array.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
import java.util.Scanner;
public class multi_array {
public static void main(String[] args) {
Scanner sr = new Scanner(System.in);
System.out.println("\tMultiplication of two matrix:");
System.out.println("Enter array size:");
int size = sr.nextInt();
int [][] a = new int[size][size];
System.out.println("\t1st array");
System.out.println("Enter array elements:");
for(int i=0; i<size; i++){
for(int j=0; j<size; j++){
a[i][j] = sr.nextInt();
}
}
int [][] b = new int [size][size];
System.out.println("\t2nd array");
System.out.println("Enter array elements:");
for(int i=0; i<size; i++){
for(int j=0; j<size; j++){
b[i][j] = sr.nextInt();
}
}
int [][] multi = new int[size][size];
for(int i=0; i<size; i++){
for(int j=0; j<size; j++){
multi[i][j]=0;
for(int k=0; k<size; k++){
multi[i][j] += a[i][k]*b[k][j];
}
}
}
System.out.println("Matrix multiplication is:");
for(int i=0; i<size; i++){
for(int j=0; j<size; j++){
System.out.print(multi[i][j]);
System.out.print("\t");
}
System.out.println("\n");
}
}
}