import java.util.*;
class Fib
{
public static void main(String args[])
{
Scanner a1=new Scanner(System.in);
System.out.println("enter the limit to generate series");
int a =a1.nextInt();
int f0=0,f1=1,f2,i;
System.out.println("Series is as follows:");
System.out.println(f0+ "\n" +f1);
for(i=1;i<=a-2;i++)
{
f2=f0+f1;
f0=f1;
f1=f2;
System.out.println(f2);
}
}
}
Output:-
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\Documents and Settings\Administrator>cd\
C:\>cd\java\bin
C:\java\bin>javac Fib.java
C:\java\bin>java Fib
enter the limit to generate series
10
Series is as follows:
0
1
1
2
3
5
8
13
21
34
No comments:
Post a Comment