Sunday, September 4, 2016

Java Program for Fibonacci series using recursion in java



  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

Bhanu Namikaze

Author & Editor

Bhanu Namikaze is an Ethical Hacker, Passionate Blogger, Web Developer, Student and Mechanical Engineer. He Enjoys writing articles, Blogging, Solving Errors, Surfing and Social Networking. Feel Free To Contact Me @ Bhanu.

0 comments:

Post a Comment

Popular Posts

Copyrights @ Interview Questions.Me - Blogger Templates Designed by Templateism - Distributed By Protemplateslab

  • (91) 5544 654942
  • Bhanu@HackingDream.net
  • Interview Questions

Copyrights @ Interview Questions.Me -A Site By Bhanu In Association With Hacking Dream