-
Notifications
You must be signed in to change notification settings - Fork 0
/
Number60.java
64 lines (63 loc) · 1.38 KB
/
Number60.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
import java.util.*;
public class Number60 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int r,c,i,j,r1,c1,d;
System.out.println("Enter number of rows and columnns of the 1st array");
r=sc.nextInt();
c=sc.nextInt();
int a[][]=new int[r][c];
System.out.println("The values of the 1st array is ");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
a[i][j]=(int)(Math.random()*100);
System.out.print(a[i][j]+" ");
}
System.out.println();
}
System.out.println("Enter number of rows and columnns of the 2st array");
r1=sc.nextInt();
c1=sc.nextInt();
int a1[][]=new int[r1][c1];
System.out.println("The values of the 2nd array is ");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
a1[i][j]=(int)(Math.random()*100);
System.out.print(a1[i][j]+" ");
}
System.out.println();
}
if(c==r1)
{
int a2[][]=new int[r][c1];
for(i=0;i<r;i++)
{
for(j=0;j<c1;j++)
{
a2[i][j]=0;
for(d=0;d<c;d++)
{
a2[i][j]+=(a[i][d]*a1[d][j]);
}
}
}
System.out.println("The multiplication of the matrix is ");
for(i=0;i<r;i++)
{
for(j=0;j<c1;j++)
{
System.out.print(a2[i][j]+" ");
}
System.out.println();
}
}
else
{
System.out.println("The multiplication of the matrix is not possible");
}
}
}