lab-03:
Throw an exception for values over 16 since it will cause an integer overflow. The Exception message is used in main the same is for -ve values.
This commit is contained in:
parent
e6b7cdc211
commit
27234cf989
@ -25,6 +25,7 @@ public class Factorials{
|
||||
|
||||
private static int factorial(int value) throws IllegalArgumentException {
|
||||
if (value < 0) throw new IllegalArgumentException("Can not calculate a negative factorial");
|
||||
if (value > 16) throw new IllegalArgumentException("Can not calculate factorials for value over 16");
|
||||
for (int i = value - 1; i > 0; i--){
|
||||
value *= i;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user