import java.io.*;
public class FibonnaciSeries
{
public void generateSeries(int num)
{
int f1, f2 = 0, f3 = 1;
System.out.println("fib(0) = " + f2);
for (int i = 1; i <= num; i++)
{
System.out.println("fib(" + i + ") = " + f3);
f1 = f2;
f2 = f3;
f3 = f1 + f2;
}
}
public static void main(String[] args) throws Exception
{
System.out.println("Fibonnaci Series");
System.out.println("Enter n value");
BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
int n;
n=Integer.parseInt(b.readLine());
FibonnaciSeries fb = new FibonnaciSeries();
fb.generateSeries(n);
}
}
No comments:
Post a Comment