import java.io.*;
import java.lang.*;
class Demo
{
int a=0,b=1,c,i=1;
void fib(int n)
{
System.out.println("Fibonacci Sequence : ");
System.out.println(" "+a);
System.out.println(" "+b);
while(i<=n-2)
{
c=a+b;
System.out.println(" "+c);
a=b;
b=c;
i++;
}
}
}
class FibonacciDemo
{
public static void main(String args[])throws IOException
{
InputStreamReader obj=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(obj);
System.out.println("enter last number");
int n=Integer.parseInt(br.readLine());
Demo ob=new Demo();
ob.fib(n);
}
}
No comments:
Post a Comment