ps0
Class Fibonacci
java.lang.Object
ps0.Fibonacci
public class Fibonacci
extends Object
Fibonacci calculates the nth term in the Fibonacci sequence.
The first two terms of the Fibonacci sequence are both 1,
and each subsequent term is the sum of the previous two terms.
Method Summary
int |
getFibTerm(int n)
Calculates the desired term in the Fibonacci sequence. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Fibonacci
public Fibonacci()
getFibTerm
public int getFibTerm(int n)
- Calculates the desired term in the Fibonacci sequence.
- Parameters:
n
- the index of the desired term; the first index of the sequence is 0
- Returns:
- the nth term in the Fibonacci sequence
- Throws:
IllegalArgumentException
- if n
is not a nonnegative number