Fibonacci Series

import java.io.*
public class FibonacciSeries  {
    public static void main(String[] args)throws IOException {
      BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
     System.out.println("Enter the number:");
     int n1=Integer.parseInt(br.readLine());
     int prev, next,sum,n;
  prev=next=1;
  for(n=1;n<=n1;n++)
  {
   System.out.println(prev);
   sum=prev+next;
   prev=next;
   next=sum;
  }

 }

}

Comments

Popular posts from this blog