Sunday, July 04, 2010

Generate Fibonacci series

Buzz It
import java.io.*;
import java.lang.*;
class fibonacci
{
int n,a=-1,b=1,c=0;
void read()
{
try
{
System.out.println("enter the limit");
DataInputStream in=new DataInputStream(System.in);
n= Integer.parseInt(in.readLine());
}
catch(Exception e)
{
System.out.println("caught exception"+e);
}
}
void gen()
{
int a=-1,b=1,c=0;
for(int i=0;i<=n;i++)
{
c=a+b;
a=b;
b=c;
System.out.println(+c);
}
}
}
class fibo
{
public static void main(String args[])
{
fibonacci f=new fibonacci();
f.read();
f.gen();
}
}


OUTPUT:

0 comments:

Post a Comment