From f1ae92771a7b049744754d35ca6701d64f4331d4 Mon Sep 17 00:00:00 2001 From: Ramtin_Jafari Date: Sun, 26 Apr 2026 18:56:15 +0330 Subject: [PATCH] modify divide instance method to throw an error when result has zero denominator --- src/main/java/Rational/Rational.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/Rational/Rational.java b/src/main/java/Rational/Rational.java index 94e31fa..b032afb 100644 --- a/src/main/java/Rational/Rational.java +++ b/src/main/java/Rational/Rational.java @@ -86,7 +86,7 @@ public class Rational { // COMPLETED - Instance method - this / other public Rational divide(Rational other) { if (other.numerator == 0) { - return null; + throw new ArithmeticException("Invalid division. Denominator will be zero"); } int newNumerator = this.numerator * other.denominator;