-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMartix.java
More file actions
43 lines (39 loc) · 1.24 KB
/
Martix.java
File metadata and controls
43 lines (39 loc) · 1.24 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
import java.util.*;
public class Martix {
public static void main(String args[])
{
Scanner kb = new Scanner(System.in);
int matrix1[][] = new int[3][3];
int matrix2[][] = new int[3][3];
int Product[][] = new int[3][3];
System.out.println("Enter a size of martix (row and column) :-");
int n = kb.nextInt();
System.out.println("Enter a matric 1 :-");
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
matrix1[i][j]=kb.nextInt();
}
}
System.out.println("Enter a matric 2 :-");
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
matrix2[i][j]=kb.nextInt();
}
}
System.out.println("the product of matrix is :- ");
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
Product[i][j]=0;
for(int k=0;k<n;k++){
Product[i][j]+=matrix1[i][k]*matrix2[k][j];
}
}
}
for(int[] row : Product) {
for (int column : row) {
System.out.print(column + " ");
}
System.out.println();
}
}
}