You want to know Java Fibonacci series then you can show this program

in #java7 years ago

In Fibonacci series, next number is the sum of previous two numbers for example 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 etc. The first two numbers of Fibonacci series are 0 and 1.
There are two ways to write the Fibonacci series program in java:
• Fibonacci Series without using recursion
• Fibonacci Series using recursion

gjcuZJsVjzrL6nvxF72eJrnF.jpeg

Fibonacci Series in Java without using recursion

Let's see the Fibonacci series program in java without using recursion.

public class FibonacciExample{

         public static void main(String[] args){
                      int fn1 = 0, fn2 = 1, rn,i, count = 10; // fn =fibonaccinumber, rn = resultnumber;
                       System.out.print(fn1+" "+fn2);  // printing 0 and 1
                  
                        for(i=2;i<count; i++){
                                rn = fn1+fn2;
                               System.out.print("  "+rn);
                                fn1=fn2;
                                fn2=rn;
                          }
         }

}

output:
0 1 1 2 3 5 8 13 21 34

PascalTriangleFibanacci.svg.png

Coin Marketplace

STEEM 0.23
TRX 0.22
JST 0.036
BTC 98604.28
ETH 3469.99
USDT 1.00
SBD 3.20