// Source code example for "A Practical Introduction // to Data Structures and Algorithm Analysis" // by Clifford A. Shaffer, Prentice Hall, 1998. // Copyright 1998 by Clifford A. Shaffer import java.io.*; // Driver class for testing factorial function class Factmain { // Compute factorial static long fact(int n) { // Must have n < 21 to fit in long Assert.notFalse((n >= 0) && (n < 21), "Input out of range"); if (n <= 1) return 1; // Base case: return base solution return n * fact(n-1); // Recursive call for n > 1 } // Main routine for factorial driver class public static void main(String args[]) throws IOException { for(int i = 1; i<25; i++) System.out.println("Factorial of " + i + " is " + fact(i)); System.in.read(); } } // class Rfactmain