Hi All,
Java program to find Fibonacci series of a given number
import java.io.*;
import java.util.*;
public class fibonacci {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter value of n: ");
String st = reader.readLine();
int num = Integer.parseInt(st);
int f1=0,f2=0,f3=1;
for(int i=1;i<=num;i++){
System.out.println(f3);
f1=f2;
f2=f3;
f3=f1+f2;
}
}
}
Output:
~~~~~~
Enter value of n: 5
1
1
2
3
5
1
1
2
3
5
No comments:
Post a Comment