### Program to implement Fibonacci series in java

Hoping you know Fibonacci series. Below is program to implement Fibonacci series in java. In below program we have taken input from user as length of Fibonacci series.

**Example of Fibonacci series**

1 |
0 1 1 2 3 5 8.... |

**Program of Fibonacci series**

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); //Take a i/p no as length of Fibonacci series System.out.println("Enter a number"); int num=sc.nextInt(); int sum=0; int first=0; int second=1; //print first two numbers System.out.print(first+" "+ second); for(int i=2;i<num;++i) { sum=first+second; first=second; second=sum; System.out.print(" " + sum); } } } |

**Output:**

1 2 3 |
Enter a number 15 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 |