Ad

A Class that helps with computing Fibonacci numbers, by treating them as linkedlist entries.

Calling FibonacciSequence next() outputs a biginteger for the current fibonacci value of the sequence's instance.

The sequence starts at 1.

import java.math.BigInteger;

public class FibonacciSequence {
	private BigInteger first;
	private BigInteger second;

	public FibonacciSequence() {
		second = BigInteger.ONE;
		first = BigInteger.ZERO;
	}

	public BigInteger next() {
		BigInteger returnVal = second;
		updateValues();
		return returnVal;
	}

	private void updateValues() {
		BigInteger t = second;
		second = first.add(t);
		first = t;
	}
}