-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultiplication.java
More file actions
84 lines (72 loc) · 1.95 KB
/
Copy pathmultiplication.java
File metadata and controls
84 lines (72 loc) · 1.95 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
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/************************************************************************************
* File :Matrix multiplication.java
* Author :prapanch j
* Description :Java Program to Multiply two Matrices
* Version :1.0
* Date :10/10/23
***********************************************************************************/
package matrix;
import java.util.Scanner;
public class multiplication {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int i,j,k;
System.out.println("enter number of row one");
int row1=sc.nextInt();
System.out.println("enter number of colum one");
int colum1=sc.nextInt();
int[][]matrix1=new int [row1][colum1];
System.out.println("enter the numbers in 1st matrix");
for(i=0;i<row1;i++){
for(j=0;j<colum1;j++){
matrix1[i][j]=sc.nextInt();
}
}
System.out.println("first matrix is");
for(i=0;i<row1;i++){
for(j=0;j<colum1;j++){
System.out.print(matrix1[i][j]+"");
}
System.out.println();
}
System.out.println("enter number of row two ");
int row2=sc.nextInt();
System.out.println("enter number of colum two");
int colum2=sc.nextInt();
int[][]matrix2=new int [row2][colum2];
int[][]matrix3=new int [row1][colum2];
System.out.println("enter the numbers in 2nd matrix");
for(i=0 ;i<row2;i++){
for(j=0;j<colum2;j++){
matrix2[i][j]=sc.nextInt();
}
}
System.out.println("2nd matrix is");
for(i=0;i<row2;i++){
for(j=0;j<colum2;j++)
{
System.out.print(matrix2[i][j]+"\t");
}
System.out.println();
}
if(colum1==row2) {
for(i=0;i<row1;i++){
for(j=0;j<colum2;j++){
matrix3[i][j]=0;
for( k=0;k<colum1;k++){
matrix3[i][j]=matrix3[i][j]+matrix1[i][k]*matrix2[k][j];
}
}
}
for(i=0;i<row1;i++){
for(j=0;j<colum2;j++){
System.out.print(matrix3[i][j]+"\t");
}
System.out.println();
}
}
else {
System.out.println("multiplication is not possible");
}
}
}