Skip to main content
8-Gravel
July 19, 2022
Solved

Fibonacci series using recursion

  • July 19, 2022
  • 1 reply
  • 1027 views

I'm attempting to produce a Fibonacci series of initial ten elements utilizing recursion. However, the compiler gives an error. Kindly assist me with tracking down the specific arrangement. 

 

The program is given below:

public class DemoJava {

 int a=0, b=1, c=0, count=10;

 public void fibonacciRecursion(count) {

 if(count>0){

 c = a+b;
 a = b;
 b = c;
 System.out.println(c);
 fibonacciRecursion(count-1);

 }
 }

 public static void main(String args[]){

 System.out.println("This is a Demo Program.");
 System.out.println(a);
 System.out.println(b);

 DemoJava dj = new DemoJava();
 dj.fibonacciRecursion((count-2));
 }
}

I have also read a couple of resources on the fibonacci series on the wiki, scaler and Quora to understand the topic in a better way. kindly help!

Best answer by nmilleson

@sachinbhatt ,

 

Could you give us a little more context around this issue?  Are you trying to write a ThingWorx extension in Java?  Or are you trying to write a JavaScript service in the Composer?

 

Thanks,

Nick

1 reply

nmilleson17-PeridotAnswer
17-Peridot
July 19, 2022

@sachinbhatt ,

 

Could you give us a little more context around this issue?  Are you trying to write a ThingWorx extension in Java?  Or are you trying to write a JavaScript service in the Composer?

 

Thanks,

Nick