-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFactorials.java
More file actions
30 lines (26 loc) · 810 Bytes
/
Factorials.java
File metadata and controls
30 lines (26 loc) · 810 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import java.util.Scanner;
// ****************************************************************
// Factorials.java
//
// Reads integers from the user and prints the factorial of each.
//
// ****************************************************************
public class Factorials {
public static void main(String[] args) {
String keepGoing = "y";
Scanner scan = new Scanner(System.in);
while (keepGoing.equals("y") || keepGoing.equals("Y")) {
System.out.print("Enter an integer: ");
int val = scan.nextInt();
try {
System.out.println("Factorial(" + val + ") = "
+ MathUtils.factorial(val));
}
catch (IllegalArgumentException problem) {
System.out.println(problem.getMessage());
}
System.out.print("Another factorial? (y/n) ");
keepGoing = scan.next();
}
}
}