-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMulMatrix.java
More file actions
42 lines (38 loc) · 982 Bytes
/
MulMatrix.java
File metadata and controls
42 lines (38 loc) · 982 Bytes
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
import java.util.*;
public class MulMatrix
{
public static void main(String[] args)
{ int row=3,col=3;
Scanner scanner = new Scanner(System.in);
int [][] m1=new int[row][col];
int [][] m2=new int[row][col];
int [][] m3=new int[row][col];
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{
m1[i][j]=scanner.nextInt();
m2[i][j]=scanner.nextInt();
}
}
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{ int sum =0;
for(int k=0;k<row;k++)
{
sum+=m1[i][k]*m2[k][j];
}
m3[i][j] = sum;
}
}
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{
System.out.print(m3[i][j]+" ");
}
System.out.println();
}
}
}