06-04-2011, 01:13 PM
Code:
import java.io.*;
class Fib
{
public static void main(String arg[])throws IOException
{
DataInputStream dim=new DataInputStream(System.in);
System.out.println("Enter the limit");
int n=Integer.parseInt(dim.readLine());
int f1=0,f2=1,f3=0;
while(f3<=n)
{
f1=f2;
f2=f3;
System.out.println(f3);
f3=f1+f2;
}
}
}
OUTPUT
E:\ 5BCA-B\lijo\java >java Fib
Enter the limit
6
0
1
1
2
3
5