/* Factorial.java CIS 111 10/29/2007 David G. Klick Calculates the factorial of integers from 0 through 20. */ public class Factorial extends CIS111App { public static void main(String[] args) { int n = 0; do { n = getInt("Enter a number (0-20) you want the factorial of (-1 to quit): "); if (n >= 0 && n <= 20) { println(n + "! = " + fact(n)); } else if (n != -1) { println("Error: Invalid input"); } } while (n != -1); } private static long fact(long n) { if (n < 2) { return 1; } else { return n * fact(n-1); } } }