-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCompareMartices.java
57 lines (50 loc) · 1.96 KB
/
CompareMartices.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
package Matrices_Lab;
import java.util.Scanner;
public class CompareMartices {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String[] input = scan.nextLine().split(" ");
int row = Integer.parseInt(input[0]);
int col = Integer.parseInt(input[1]);
int matrix [][] = new int[row][col];
for (int r = 0; r < row; r++) {
String[] numbers = scan.nextLine().split(" ");
for (int c = 0; c < col; c++) {
matrix[r][c] = Integer.parseInt(numbers[c]);
}
System.out.println();
}
String[] secondMatrixInput = scan.nextLine().split(" ");
int rowSecondMatrix = Integer.parseInt(secondMatrixInput[0]);
int colSecondMatrix = Integer.parseInt(secondMatrixInput[1]);
int matrixSecond [][] = new int[rowSecondMatrix][colSecondMatrix];
for (int r2 = 0; r2 < rowSecondMatrix; r2++) {
String[] numberSecondMatrix = scan.nextLine().split(" ");
for (int c2 = 0; c2 < colSecondMatrix; c2++) {
matrixSecond[r2][c2] = Integer.parseInt(numberSecondMatrix[c2]);
}
System.out.println();
}
if(row == rowSecondMatrix && col == colSecondMatrix ){
if(isEqual(matrix,matrixSecond,row,col)){
System.out.println("equal");
}else{
System.out.println("not equal");
}
}else{
System.out.println("not equal");
}
}
private static boolean isEqual(int[][] matrix, int[][] matrixSecond, int row, int col) {
for (int r = 0; r < row; r++) {
for (int c = 0; c < col; c++) {
int num1 = matrix[r][c];
int num2 = matrixSecond[r][c];
if (num1 != num2) {
return false;
}
}
}
return true;
}
}