Author: techfox9
Fibonacci algorithm recursive
Wednesday, January 28th, 2015 @ 1:23 am
from http://javadecodedquestions.blogspot.com/2013/01/java-interviews-frequently-asked-puzzles.html
[java]
public class FibonacciNumber {
public static int fibonacci(int n) {
if (n < 2) {
return n;
}
else {
return fibonacci(n – 1) + fibonacci(n – 2);
}
}
}
[/java]
from http://stackoverflow.com/questions/8965006/java-recursive-fibonacci-sequence
[java]
public int fibonacci(int n) {
if(n == 0)
return 0;
else if(n == 1)
return 1;
else
return fibonacci(n – 1) + fibonacci(n – 2);
}
[/java]