-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArrayMultiply.java
68 lines (48 loc) · 1.78 KB
/
ArrayMultiply.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
68
import java.util.Scanner;
public class ArrayMultiply {
static int arr1[][] = new int [3][3];
static int arr2[][] = new int [3][3];
public static void Multiplication() {
System.out.println("\nMultiplication :");
int arr3[][] = new int [3][3];
for(int i=0; i<arr3.length; i++) {
for(int j=0; j<arr3[i].length; j++) {
arr3[i][j] = 0;
for(int k=0;k<3;k++) {
arr3[i][j]+=arr1[i][k]*arr2[k][j];
}
}
}
System.out.println(arr1[0][0]+" " + arr1[0][1] + " " + arr1[0][2] + " "+arr2[0][0]+" "+arr2[0][1]+" "+arr2[0][2]+" "+arr3[0][0]+" "+arr3[0][1]+" "+arr3[0][2]);
System.out.println(arr1[1][0]+" " + arr1[1][1] + " " + arr1[1][2] + " * "+arr2[1][0]+" "+arr2[1][1]+" "+arr2[1][2]+" = "+arr3[1][0]+" "+arr3[1][1]+" "+arr3[1][2]);
System.out.println(arr1[2][0]+" " + arr1[2][1] + " " + arr1[2][2] + " "+arr2[2][0]+" "+arr2[2][1]+" "+arr2[2][2]+" "+arr3[2][0]+" "+arr3[2][1]+" "+arr3[2][2]);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
for(int i=0; i<arr1.length; i++) {
for(int j=0; j<arr1[i].length; j++) {
System.out.print("Enter a number for arr1["+i+"]["+j+"]: ");
arr1[i][j] = sc.nextInt();
}
}
for(int i=0; i<arr1.length; i++) {
for(int j=0; j<arr1[i].length; j++) {
System.out.print(arr1[i][j]+" ");
}
System.out.println();
}
for(int i=0; i<arr2.length; i++) {
for(int j=0; j<arr2[i].length; j++) {
System.out.print("Enter a number for arr2["+i+"]["+j+"]: ");
arr2[i][j] = sc.nextInt();
}
}
for(int i=0; i<arr2.length; i++) {
for(int j=0; j<arr2[i].length; j++) {
System.out.print(arr2[i][j]+" ");
}
System.out.println();
}
Multiplication();
}
}