cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

Fibonacci series using recursion

sachinbhatt
8-Gravel

Fibonacci series using recursion

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!

ACCEPTED SOLUTION

Accepted Solutions

@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

View solution in original post

1 REPLY 1

@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

Announcements


Top Tags