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

Fibonacci Series Program in Java using Loops

What is Fibonacci Series?
In Fibonacci series, next number is the sum of previous two numbers. The first two numbers of Fibonacci series are 0 and 1.

The Fibonacci numbers are significantly used in the computational run-time study of algorithm to determine the greatest common divisor of two integers.In arithmetic, the Wythoff array is an infinite matrix of numbers resulting from the Fibonacci sequence.

The Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, ...

Program:
class Fibonacci_loop
{
  public static void main(String[] args)
     {
      // Set it to the number of elements you want in the Fibonacci Series
       int maxNumber = 10;
       int previousNumber = 0;
       int nextNumber = 1;
       System.out.print("Fibonacci Series of "+maxNumber+" numbers:");
             for (int i = 1; i <= maxNumber; ++i)
             {
                 System.out.print(previousNumber+" ");
                 /* On each iteration, we are assigning second number
                  * to the first number and assigning the sum of last two
                  * numbers to the second number
                  */
                 int sum = previousNumber + nextNumber;
                 previousNumber = nextNumber;
                 nextNumber = sum;
             }
  }
}
Output:
Fibonacci Series of 10 numbers: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!