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