Sunday, October 21, 2012

Java program to print fibonacci series upto a given number

import java.io.*;
class Fibonacci
{ int next,curr,prev,num;
            Fibonacci(int a)
  { next=1;
     curr=1;
    prev=0;
    num=a;  }
  void calc()
  { while(prev<=num)
    { System.out.println(prev);
      prev=curr;
      curr=next;
      next=prev+curr;  }
  }
  public static void main(String s[])throws IOException
  { BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    System.out.println("Enter the limit");
    int a=Integer.parseInt(br.readLine());
    Fibonacci f=new Fibonacci(a);
    f.calc(); }
}
Output


3 comments:

  1. Thank you for sharing this blog with some interesting topic keep doing this work also check out this Best CBSE School in Faridabad

    ReplyDelete
  2. What a wonderful blog it has everything and helps me to understand new things keep updating also have a look on this Best School in Faridabad

    ReplyDelete