Q:

Write a Java Program to display Fibonacci Series using While Loop

0

Fibonacci series is in the form of 1, 1, 2, 3, 5, 8, 13, 21,……

To find this series we add two previous terms/digits and get next term/number.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

SOURCE CODE :

import java.util.Scanner;

public class Fibonacci {

  
    public static void main(String[] args) {
        
        int a=1,b=1,n,fibon=1;
              
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter how many terms u want : ");
        n=sc.nextInt();
        System.out.print(fibon);
        while(n>1)
        {
             System.out.print(" "+fibon);
             fibon=a+b;
             a=b;
             b=fibon;
             n--;
        }
         System.out.println("");
        
    }
    
}

OUTPUT :: 

Enter how many terms u want : 
11
1 1 2 3 5 8 13 21 34 55 89

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now