/** * Title: Chapter 4, "Methods" * Description: Examples for Chapter 4 * Copyright: Copyright (c) 2000 * Company: Armstrong Atlantic State University * @author Y. Daniel Liang * @version 1.0 */ // ComputeFibonacci.java: Find a Fibonacci number for a given index // package chapter4; public class ComputeFibonacci { /**Main method*/ public static void main(String args[]) { // Read the index System.out.println("Enter an index for the Fibonacci number"); int n = MyInput.readInt(); // Find and display the Fibonacci number System.out.println("Fibonacci number at index " + n + " is "+fib(n)); } /**The method for finding the Fibonacci number*/ public static long fib(long n) { if ((n==0)||(n==1)) // Stopping condition return 1; else // Reduction and recursive calls return fib(n-1) + fib(n-2); } }