Infolinks In Text Ads

Nov 12, 2010

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);
        }
    }
}

No comments:

Post a Comment

LinkWithin

Related Posts Plugin for WordPress, Blogger...