Catch thrown exception in main and cont. the program.
This commit is contained in:
HeshamTB 2020-10-15 06:40:23 +03:00
parent 3413b10185
commit e6b7cdc211
Signed by: Hesham
GPG Key ID: 74876157D199B09E

View File

@ -11,7 +11,12 @@ public class Factorials{
System.out.print("Enter an integer: ");
int val = scan.nextInt();
System.out.println("Factorial(" + val + ") = " + factorial(val));
try {
System.out.println("Factorial(" + val + ") = " + factorial(val));
}
catch (IllegalArgumentException ex){
System.out.println(ex.getMessage() + String.format(" (%d)", val));
}
System.out.print("Another factorial? (y/n) ");
keepGoing = scan.next();