Throw illegalArg Exception when a negative value is passed to factorial().
This commit is contained in:
HeshamTB 2020-10-15 06:35:10 +03:00
parent ad85cbea6c
commit 3413b10185
Signed by: Hesham
GPG Key ID: 74876157D199B09E

View File

@ -18,8 +18,8 @@ public class Factorials{
} }
} }
private static int factorial(int value){ private static int factorial(int value) throws IllegalArgumentException {
if (value < 0) throw new IllegalArgumentException("Can not calculate a negative factorial");
for (int i = value - 1; i > 0; i--){ for (int i = value - 1; i > 0; i--){
value *= i; value *= i;
} }