-
Notifications
You must be signed in to change notification settings - Fork 1.9k
handle when divisor b is zero in all division methods in Division.Java #249
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
base: master
Are you sure you want to change the base?
handle when divisor b is zero in all division methods in Division.Java #249
Conversation
after reviewing the code, each method in Division.java has a new if statement to throw an illegal argument error if the divisor b is zero. |
@@ -3,11 +3,17 @@ | |||
public class Division { | |||
|
|||
public static final long division(int a, int b) { | |||
if (b == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
catches if divisor b is 0
long result = ((long) a) / ((long) b); | ||
return result; | ||
} | ||
|
||
public static final long divisionUsingLoop(int a, int b) { | ||
if (b == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
catches if divisor b is 0
@@ -22,6 +28,9 @@ public static final long divisionUsingLoop(int a, int b) { | |||
} | |||
|
|||
public static final long divisionUsingRecursion(int a, int b) { | |||
if (b == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
catches if divisor b is 0
@@ -38,6 +47,9 @@ public static final long divisionUsingRecursion(int a, int b) { | |||
} | |||
|
|||
public static final long divisionUsingMultiplication(int a, int b) { | |||
if (b == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
catches if divisor b is 0
@@ -55,6 +67,9 @@ public static final long divisionUsingMultiplication(int a, int b) { | |||
} | |||
|
|||
public static final long divisionUsingShift(int a, int b) { | |||
if (b == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
catches if divisor b is 0
@@ -76,6 +91,9 @@ public static final long divisionUsingShift(int a, int b) { | |||
} | |||
|
|||
public static final long divisionUsingLogs(int a, int b) { | |||
if (b == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
catches if divisor b is 0
This PR modifies all methods in Division.java to handle when the divisor, b is zero. This prevents potential runtime errors and improves the robustness of the code.