Class Fibonacci

  • All Implemented Interfaces:
    Sequence

    public class Fibonacci
    extends Object
    implements Sequence
    A Fibonacci sequence starts with 0 and 1 as the first two numbers. Each subsequent number is the sum of the previous two. For example,
    0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
    See Also:
    Wikipedia: Fibonacci number
    • Constructor Detail

      • Fibonacci

        public Fibonacci​(int length)
        Construct a Fibonacci sequence.
        Parameters:
        length - the number of terms to generate
    • Method Detail

      • length

        public int length()
        Description copied from interface: Sequence
        Get the number of computed terms in the sequence.
        Specified by:
        length in interface Sequence
        Returns:
        the length of sequence
      • get

        public double get​(int i)
        Description copied from interface: Sequence
        Get the i-th entry in the sequence, counting from 1.
        Specified by:
        get in interface Sequence
        Parameters:
        i - an index
        Returns:
        the i-th entry in the sequence
      • getAll

        public double[] getAll()
        Description copied from interface: Sequence
        Get a copy of the whole (finite) sequence in double[].
        Specified by:
        getAll in interface Sequence
        Returns:
        a copy of all the computed terms in the sequence