Package cpsc331

Class 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Fibonacci

        public Fibonacci()
    • 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.An IllegalArgumentException 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