Fibonacci series program in java
The below code is arrnging fibonacci series progrm in java,fibonacci series program in java with example,program for fibonacci series, import java.io.*;
class Fibanancci{
public static void main(String a[])throws IOException{
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
System.out.println("how many fibonacci?");
int n=Integer.parseInt(br.readLine());
long f1=0,f2=1;
System.out.println(f1);
System.out.println(f2);
long f=f1+f2;
System.out.println(f);
//already 3 fibonacci are displayed so count will start at 3
int count=3;
while(count<n){
f1=f2;
f2=f;
f=f1+f2;
System.out.println(f);
count++;
}
}
}
out put of fibonacci series program in java
C:\>d:
D:\>cd javaprog
D:\javaprog>javac Fibanancci.java
D:\javaprog>java Fibanancci
how many fibonacci? 10
1
1
2
3
5
8
13
21
34
No comments:
Post a Comment