Fibonacci numbers are recursive. They are generated by the sum of the predecessor and the predecessor’s predecessor, or more formal:
/* In 1202, Fibonacci published the Liber
Abaci, introducing not only the arabic
numerals, but also algorithms to occidental
mathematics. It contains a famous series of
numbers, generated by a recursive method
which calls itself as a method which calls
itself as a method which calls itself as ...
until the initial value n=1 is reached. Then
it returns to the start adding the numbers */
public static int fib(int n) {
if (n <= 1) return n;
else return fib(n-1) + fib(n-2);
}
A more extensive commentary on Fibonacci and recursions can soon be found here github.com/nachsommer/interlocutor.