FileDocCategorySizeDatePackage
FibonacciImpl.javaAPI DocExample943Sun Dec 12 10:56:02 GMT 2004None

FibonacciImpl

public class FibonacciImpl extends UnicastRemoteObject implements Fibonacci

Fields Summary
Constructors Summary
public FibonacciImpl()

    super();
  
Methods Summary
public java.math.BigIntegergetFibonacci(int n)

    return this.getFibonacci(new BigInteger(Long.toString(n)));  
  
public java.math.BigIntegergetFibonacci(java.math.BigInteger n)

  
    
    System.out.println("Calculating the " + n + "th Fibonacci number");
    BigInteger zero = new BigInteger("0");
    BigInteger one  = new BigInteger("1");
    
    if (n.equals(zero)) return one;
    if (n.equals(one)) return one; 

    BigInteger i  = one;
    BigInteger low  = one;
    BigInteger high  = one;

    while (i.compareTo(n) == -1) {
      BigInteger temp = high;
      high = high.add(low);
      low = temp; 
      i = i.add(one);
    }

    return high;