lab-03:
Catch thrown exception in main and cont. the program.
This commit is contained in:
parent
3413b10185
commit
e6b7cdc211
@ -11,7 +11,12 @@ public class Factorials{
|
|||||||
|
|
||||||
System.out.print("Enter an integer: ");
|
System.out.print("Enter an integer: ");
|
||||||
int val = scan.nextInt();
|
int val = scan.nextInt();
|
||||||
|
try {
|
||||||
System.out.println("Factorial(" + val + ") = " + factorial(val));
|
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) ");
|
System.out.print("Another factorial? (y/n) ");
|
||||||
keepGoing = scan.next();
|
keepGoing = scan.next();
|
||||||
|
Loading…
Reference in New Issue
Block a user