Sunday, July 30, 2017

Fibonacci series example in Java

public class febSeries {

  public int f1=0;
 public int f2=1;
 public int f3;
 
 public static int febser(int n){  
  
  if(n==0){
   return 0;
  }if(n==1){
   return 1;
  }
  int f1=0;
  int f2=1;
  int f3=1;
  
  for(int i=2;i<=n;i++){
   f3=f1+f2;
   f1=f2;
   f2=f3;
  }
  return f3;
 } 
 public static void main(String[] args) {
  
  for(int i=0;i<20 font="" i="">
   
   System.out.println(febser(i)+" ");
  }
 }
}