I have to write a small program computing the fibonaccisequence using recursion.
ID: 3615311 • Letter: I
Question
I have to write a small program computing the fibonaccisequence using recursion. I have been able to properly writethe recursive method, but I cannot get the print lines to beproper. The instructions want the print out to looklike: Fibonacci #1 = 0 Fibonacci #2 = 1 Fibonacci #3 = 1 Fibonacci #4 = 2 this has to keep repeating until it reaches the number thatwas entered by the user. I can only pass variables throughparameters so I am unable to print the correct value for eachline. Here is what I have for my print statement. fibonacciNumber =keyboard.nextInt();int x = 1;
while (x <=fibonacciNumber) {
System.out.println("Fibonacci #" + x + " = " fib(n));
x++; n is my parameter for my recursion method but it will not berecognized in main method. How can I create a variable toprint out the proper number. Will rate ASAP for help in thismatter. I have to write a small program computing the fibonaccisequence using recursion. I have been able to properly writethe recursive method, but I cannot get the print lines to beproper. The instructions want the print out to looklike: Fibonacci #1 = 0 Fibonacci #2 = 1 Fibonacci #3 = 1 Fibonacci #4 = 2 this has to keep repeating until it reaches the number thatwas entered by the user. I can only pass variables throughparameters so I am unable to print the correct value for eachline. Here is what I have for my print statement. fibonacciNumber =keyboard.nextInt();
int x = 1;
while (x <=fibonacciNumber) {
System.out.println("Fibonacci #" + x + " = " fib(n));
x++; n is my parameter for my recursion method but it will not berecognized in main method. How can I create a variable toprint out the proper number. Will rate ASAP for help in thismatter.