package rebelsky.exam1; import java.math.BigInteger; /** * Something that counts the number of times a method is * called. */ public class Fib { /** A count of the number of times the method is called. */ static long calls; /** Get the number of times the method is called. */ public static long getCalls() { return calls; } /** Reset the count to 0. */ public static void reset() { calls = 0; } /** * Compute the nth Fibonacci number. The Fibonacci numbers * are given by the rules * * The 0th Fibonacci number is 1 * * The 1st Fibonacci number is 1 * * The nth Fibonacci numbers is the sum of * the n-1st Fibonacci number and the n-2nd Fibonacci number * That is, the sequence * 1, 1, 2, 3, 5, 8, 13, 21, .... */ public static BigInteger fib(int n) { calls = calls+1; if (n < 2) { return BigInteger.ONE; } else { return fib(n-1).add(fib(n-2)); } } } // class Fib