-
Notifications
You must be signed in to change notification settings - Fork 1.9k
An error handling for division by zero was added by throwing IllegalA… #261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…rgumentException in the methods of Division.java.
|
||
public static final long division(int a, int b) { | ||
if (b == 0){ | ||
throw now IllegalArgumentException ("Denominator is 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.
Alerting user the denominator is zero.
int absB = Math.abs(b); | ||
|
||
if (b == 0){ | ||
throw now IllegalArgumentException ("Denominator is 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.
Checks if denominator is 0 before the rest of the division process is complete.
int absB = Math.abs(b); | ||
|
||
if (b == 0){ | ||
throw now IllegalArgumentException ("Denominator is 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.
Checks if denominator is 0 before the rest of the division process is complete.
int absB = Math.abs(b); | ||
|
||
if(b == 0){ | ||
throw now IllegalArgumentException ("Denominator is 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.
Checks if denominator is 0 before the rest of the division process is complete.
int tempA, tempB, counter; | ||
|
||
if(b == 0){ | ||
throw now IllegalArgumentException ("Denominator is 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.
Checks if denominator is 0 before the rest of the division process is complete.
long absB = Math.abs(b); | ||
|
||
if(b == 0){ | ||
throw now IllegalArgumentException ("Denominator is 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.
Checks if denominator is 0 before the rest of the division process is complete.
…rgumentException in the methods of Division.java.
In this change I added if statements in each of the methods of Division to throw an IllegalArgumentException if the divisor (b) equaled 0. This allows the user to know when an error occurred with the inputted values.
By submitting this pull request I confirm I've read and complied with the below requirements.
Added {Algorithm/DS name} [{Language}]
, notUpdate README.md
orAdded new code
.