package fib; import java.math.BigInteger; /** * Fibonacci numbers. * * @author Samuel Rebelsky * @author Angeline Namai * @version Version 1.0 of October 2004. */ public class Computer { // +-----------+--------------------------------------------------------- // | Observers | // +-----------+ /* public long fib(int n) { long[] values = new long[n+1]; values[0] = 0; values[1] = 1; for (int i = 2; i <= n; i++) { values[i] = values[i-1] + values[i-2]; } // for(int) return values[n]; } // fib(int) */ /** * Compute the nth fibonacci number and return the result as a BigInteger. */ public BigInteger fib(int n) { // Sanity check: Do the easy ones without the array. if (n < 2) return BigInteger.valueOf(n); BigInteger[] values = new BigInteger[n+1]; values[0] = BigInteger.valueOf(0); values[1] = BigInteger.valueOf(1); for (int i = 2; i <= n; i++) { values[i] = values[i-1].add(values[i-2]); } // for(int) return values[n]; } // fib(int) } // class Computer