Fibonacci Series using Recursion

Fibonacci Series using Recursion

Fibonacci Series - Fibonacci Series is the addition of before two digits, You can achieve
Fibonacci Series using Recursion and with out making any global variable through this program.

public class Test {
   
    public static void main(String[] args) {
        Test test = new Test();
        test.getFibonacciSeries(0,1, false);
    }
   
    void getFibonacciSeries(int x, int y, boolean s){
        if(x == 0)
            System.out.println(x);
        if(y == 1 && !s){
            System.out.println(y);
            s=true;
        }
        System.out.println(x+y);
        if(x+y < 40){
            getFibonacciSeries(y, x+y, s);
        }
    }
}

Comments

Recent Post

Recent Posts Widget

Popular posts from this blog

Capture image from webcam java code, examples

How to capture finger prints in java

Shallow Copy Deep Copy Java example