import java.util.Scanner;
public class Fibonacci
{
public static void main(String args[])
{
int n, i, first = 0, second = 1, next;
System.out.println("Enter the number of terms");
Scanner enter = new Scanner(System.in);
n = enter.nextInt();
System.out.println("Fibonacci series are");
for (i = 0 ; i < n ; i++)
{
if (i <= 1)
next = i;
else
{
next = first + second;
first = second;
second = next;
}
System.out.println(next);
}
}
}
Output….
Enter the number of terms
5
Fibonacci series are
0
1
1
2
3