From 10932ccab197aeb8dea5d2f60caff6eaec690d92 Mon Sep 17 00:00:00 2001 From: Egoscio Date: Thu, 21 Mar 2019 14:33:14 -0700 Subject: [PATCH] Comparing Matrix size before content size. --- DataStructures/Matrix/Matrix.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/DataStructures/Matrix/Matrix.java b/DataStructures/Matrix/Matrix.java index 2723e7bc..dc1ac426 100644 --- a/DataStructures/Matrix/Matrix.java +++ b/DataStructures/Matrix/Matrix.java @@ -211,11 +211,14 @@ public class Matrix { * @return boolean */ public boolean equals(Matrix other) { + if (this.getRows() != other.getRows() || this.getColumns() != other.getColumns()) + return false; + for (int i = 0; i < this.data.length; i++) for (int j = 0; j < this.data[0].length; j++) if (this.data[i][j] != other.data[i][j]) return false; - + return true; }