Package cpsc331
Class Fibonacci
- java.lang.Object
-
- cpsc331.Fibonacci
-
public class Fibonacci extends java.lang.Object
A class for the computation of Fibonacci numbers.Computes the nth Fibonacci number, Fn, when a non-negative integer n is given as a single command-line input.
-
-
Constructor Summary
Constructors Constructor Description Fibonacci()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.math.BigInteger
eval(int n)
Computes the nth Fibonacci number, Fn, throwing an IllegalArgumentException if n is negative.static void
main(java.lang.String[] args)
The main method for this class.
-
-
-
Method Detail
-
main
public static void main(java.lang.String[] args)
The main method for this class.- Parameters:
args
- should be a single non-negative integer n.
-
eval
public static java.math.BigInteger eval(int n)
Computes the nth Fibonacci number, Fn, throwing an IllegalArgumentException if n is negative.
Precondition:
An integer n is given as input.
Postcondition:
If n ≥ 0 then the nth Fibonacci number, Fn, is returned as output.AnIllegalArgumentException
is thrown, otherwise.- Parameters:
n
- the integer whose Fibonacci number is to be computed- Returns:
- the nth Fibonacci number, Fn
- Throws:
java.lang.IllegalArgumentException
- if the input is negative
-
-