Java program to find fibonacci series

import java.io.*;
import java.util.*;
class fibonacci
{
public static void main(String args[])
{
int num,num1=0,num2=1,num3;
System.out.println(“Enter the limitn”);
Scanner sc= new Scanner(System.in);
num=sc.nextInt();
System.out.println(num1);
System.out.println(num2);
for(int i=2;i<num;i++) //already printed two numbers 0 and 1 that’swhy our i initiiialize from 2 skipping first two iteration
{

num3=num1+num2;
num1=num2;
    num2=num3;
System.out.println(num3);
}

}
}

OUTPUT-
Enter the limit
5
0
1
1
2
3

Leave a Comment

Your email address will not be published. Required fields are marked *

Hire a server Expert to resolve the issue Now.

Hire a server Expert to resolve the issue Now.

Resolve this issue in just 5$ from https://serverexpert.io

 

You have Successfully Subscribed!

Open chat