modify divide instance method to throw an error when result has zero denominator

This commit is contained in:
2026-04-26 18:56:15 +03:30
parent 31cebd8cc6
commit f1ae92771a
+1 -1
View File
@@ -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;