» » Fibonacci series using recursion in java

  1. package com.instaceofjavaforus;
      public class FibanacciRecursive {
    public void fibanci(int n1,int n2){
    int sum=0;
    if(n1==0){
    System.out.println(n1+"\n"+n2);
    }
    sum=n1+n2;
    if(sum<=100){
    System.out.println(sum);
    n1=n2;
    n2=sum;

    fibanci(n1,n2);

    }
    }

    public static void main(String[] args) {

          FibanacciRecursive fb=new FibanacciRecursive();
          fb.fibanci(0,1);
    }

    }
    Output:
    0
    1
    1
    2
    3
    5
    8
    13
    21
    34
    55
    89

Instance Of Java

We will help you in learning.Please leave your comments and suggestions in comment section. if you any doubts please use search box provided right side. Search there for answers thank you.
«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply

Select Menu