Fibonacci series

import java.util.*;
import java.util.Scanner;
class fibonacciSeries
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("please enter a number to print fibonacci series");
int num=sc.nextInt();
System.out.println("***Fibonacci Series***");
int f1,f2=0,f3=1;
for(int i=1;i<=num;i++)
{
System.out.print(" "+f3+" ");
f1=f2;
f2=f3;
f3=f1+f2;
}
}
}
OUTPUT:
please enter a number to print fibonacci series
9
***Fibonacci Series***
1  2  3  5  8  13  21  34 
Translate »