/* File: FacRec.java - March 2011 */ package l04; /** * Compute and display the factorial of the input argument * using a recursive algorithm * * Sample usage: java l04.FacRec 5 * * @author Michael Albert * */ public class FacRec{ public static void main(String[] args) { int n = Integer.parseInt(args[0]); System.out.println(n + "! = " + factorial(n)); } public static long factorial(int n) { if (n < 0) throw new ArithmeticException("Factorial not defined on " + n); if (n == 0) return 1; return n*factorial(n-1); } }