-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEqualMatrix.java
More file actions
53 lines (44 loc) · 1.68 KB
/
EqualMatrix.java
File metadata and controls
53 lines (44 loc) · 1.68 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
package practice;
public class EqualMatrix
{
public static void main(String[] args) {
int row1, col1, row2, col2;
boolean flag = true;
//Initialize matrix a
int a[][] = {
{1, 2, 3},
{8, 4, 6},
{4, 5, 7}
};
//Initialize matrix b
int b[][] = {
{1, 2, 3},
{8, 4, 6},
{4, 5, 7}
};
//Calculates the number of rows and columns present in the first matrix
row1 = a.length;
col1 = a[0].length;
//Calculates the number of rows and columns present in the second matrix
row2 = b.length;
col2 = b[0].length;
//Checks if dimensions of both the matrices are equal
if(row1 != row2 || col1 != col2){
System.out.println("Matrices are not equal");
}
else {
for(int i = 0; i < row1; i++){
for(int j = 0; j < col1; j++){
if(a[i][j] != b[i][j]){
flag = false;
break;
}
}
}
if(flag)
System.out.println("Matrices are equal");
else
System.out.println("Matrices are not equal");
}
}
}