Create a class that will print out the set of Fibonacci numb
Create a class that will print out the set of Fibonacci numbers that will be calculated in a loop that runs
for 50 iterations. A Fibonacci number follows the sequence 0, 1, 1, 2, 3, 5, 8, 11, etc. where each number is
the sum of the two numbers before it.
Solution
Here is the code for you:
class FibonacciNumber
{
public static long calcFibonacciR(int index)
{
if(index == 0)
return 0;
else if(index == 1)
return 1;
else
return calcFibonacciR(index-1) + calcFibonacciR(index-2);
}
public static void main(String[] args)
{
int n = 50;
for(int i = 0; i <= 50; i++)
System.out.print(calcFibonacciR(i) + \" \");
System.out.println();
}
}
