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 are here to help you learn! Feel free to leave your comments and suggestions in the comment section. If you have any doubts, use the search box on the right to find answers. Thank you! 😊
«
Next
Sort the string using String Methods?
»
Previous
Fibonacci series without using recursion in java

No comments

Leave a Reply

Select Menu