So, for example if I had a method called "divide" and it would just divide to ints and return an int, what would be the best way to check that the divisor is != 0
Way 1:
private int divide(int i1, int i2) {
if(i2 == 0) return 0;
return i1/i2;
}
Way 2:
private int divide(int i1, int i2) {
if(i2 != 0) {
return i1/i2;
} else {
return 0;
}
}
Which one would you prefer?
EDIT: I know, that you'd normally not write such a function, since it would throw an exception if the divisor is 0 anyways. This is just to clearify my question.
EDIT 2: I just changed the method function to return 0, if the divisor is 0.