// **************************************************************** // Factorials.java // // Reads integers from the user and prints the factorial of each. // // **************************************************************** import java.io.*; public class Factorials { public static void main(String[] args) throws IOException { BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in)); char keepGoing = 'y'; while (keepGoing == 'y' || keepGoing == 'Y') { System.out.print("\nEnter an integer: "); int val = Integer.parseInt(keyboard.readLine()); System.out.println("Factorial(" + val + ") = " + MathUtils.factorial(val) + '\n'); System.out.print("Another factorial? (y/n) "); keepGoing = (char) keyboard.read(); // read 1 character answer keyboard.readLine(); // read newline char } } }