public final class FibonacciCounter
extends java.lang.Object
An integer factor can be applied at construction, so that the numbers returned are a multiple of the factor. The default factor is 1.
Modifier and Type | Field and Description |
---|---|
private long |
current
Current number in the series
|
private int |
factor
Factor to multiply with each number in the series
|
private long |
previous
Previous number in the series
|
Constructor and Description |
---|
FibonacciCounter()
Default constructor, which uses a factor of 1.
|
FibonacciCounter(int factor)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
long |
current()
Report the current number in the series, multiplied by the factor.
|
static void |
main(java.lang.String[] args)
Syntax:
FibonacciCounter [count [factor]] , where count is a positive
number of sequence elements to display and factor is the factor to apply to each
element. |
long |
next()
Advance to the next number in the series, making it the current number, and report it
multiplied by the factor.
|
void |
reset()
Reset the series back to the starting number of 1.
|
private final int factor
private long previous
private long current
public FibonacciCounter()
public FibonacciCounter(int factor)
factor
- Factor to multiply with each number in the series. Does not change the series,
only the number reported.public long current()
public long next()
current()
will report the same
number reported by this method, until this method is invoked again.public void reset()
public static void main(java.lang.String[] args)
FibonacciCounter [count [factor]]
, where count
is a positive
number of sequence elements to display and factor
is the factor to apply to each
element.args
- See above.