/* Factorial.java CIS 160 David Klick 2007-10-30 Calculates the factorial of integers from 0 through 20. */ import java.util.Scanner; public class Factorial { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = 0; do { System.out.print("Enter a number (0-20) you want the factorial of (-1 to quit): "); n = in.nextInt(); if (n >= 0 && n <= 20) { System.out.println(n + "! = " + fact(n)); } else if (n != -1) { System.out.println("Error: Invalid input"); } } while (n != -1); } private static long fact(long n) { if (n < 2) { return 1; } else { return n * fact(n-1); } } }