We are uploading our contents, please refresh app.
Java Premium

Write a program in java to accept a range and print the Fibonacci series

Fibonacci Series generates subsequent number by adding two previous numbers. Fibonacci series starts from two numbers − F0 and F1. The initial values of F0 and F1 can be taken 0, 1 or 1, 1 respectively.

Fn = Fn-1 + Fn-2

Algorithm

1. Take integer variable A, B, C
2. Set A = 1, B = 1
3. DISPLAY A, B
4. C = A + B
5. DISPLAY C
6. Set A = B, B = C
7. REPEAT from 4 - 6, for n times

Program:
import java.util.*;
class Fibonacci_Series
{
  public static void main(String args[])
  {
    int n,a=0,b=1,c,i;
    Scanner sc=new Scanner(System.in);
    System.out.println("Enter the number to print the fibonacci series :");
    n=sc.nextInt();
    System.out.println("Fibonacci series is:");
    System.out.print(a+","+b+",");
    for(i=3;i<=n;i++)
    {
    c=a+b;
    System.out.print(c+",");
    a=b;
    b=c;
    }
  }
}
Output:
Enter the number to print the fibonacci series :
Fibonacci series is:
0,1,1,2,3,5,8,13,21,34,

Online user

Download our android app Download App Submit your query
x

Get Updates On

Java & Premium Programs

Java Solved & Questions

Java Coding easy to use

Proper Coding

Straight Into Your INBOX!

We are going to send you our resources for free. To collect your copy at first, join our mailing list. We are promising not to bother you by sending useless information. So don't miss any updates, stay connected!