public class FactorialCalculator
1: // Fig. 15.10: FactorialCalculator.java
2: // Iterative factorial method.
3:
4: public class FactorialCalculator
5: {
6: // recursive declaration of method factorial
7: public long factorial( long number )
8: {
9: long result = 1;
10:
11: // iterative declaration of method factorial
12: for ( long i = number; i >= 1; i-- )
13: result *= i;
14:
15: return result;
16: } // end method factorial
17:
18: // output factorials for values 0-10
19: public void displayFactorials()
20: {
21: // calculate the factorials of 0 through 10
22: for ( int counter = 0; counter <= 10; counter++ )
23: System.out.printf( "%d! = %d\n", counter, factorial( counter ) );
24: } // end method displayFactorials
25: } // end class FactorialCalculator
26:
27: /*************************************************************************
28: * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and *
29: * Pearson Education, Inc. All Rights Reserved. *
30: * *
31: * DISCLAIMER: The authors and publisher of this book have used their *
32: * best efforts in preparing the book. These efforts include the *
33: * development, research, and testing of the theories and programs *
34: * to determine their effectiveness. The authors and publisher make *
35: * no warranty of any kind, expressed or implied, with regard to these *
36: * programs or to the documentation contained in these books. The authors *
37: * and publisher shall not be liable in any event for incidental or *
38: * consequential damages in connection with, or arising out of, the *
39: * furnishing, performance, or use of these programs. *
40: *************************************************************************/