Answers for "fibunacci java"

3

fibunacci java

// WARNING: The function assumes that 'fib(0)=0' and 'fib(1)=1'
// Returns the number of the fibonacci sequence at index 'n'
public static int fib(int n) {
	if (n < 2) // No difference if '<' or '<=', because 'fib(2)=2'.
		return n;
	return fib(n-1) + fib(n-2); // Uses the recursion method for solving
}
Posted by: Guest on November-02-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language