I have seen many examples of Fibonacci here on Stack Overflow but I have found no answer for my question. So, I have a code:
public class Fib {
public static int fib(int n) {
if (n < 2) {
return n;
}
else {
return fib(n-1)+fib(n-2);
}
}
public static void main(String[] args) {
for (int i=0; i<8; i++)
System.out.print(fib(i)+", ");
}
}
After run it we will get 0, 1, 1, 2, 3, 5, 8, 13,
I have a question: How do we get 8 ? fib(6)=............
Can anyone write in detail?