In this Blog we are going to learn how to print fibonnaci series in java without using recursion

So what is Fibonnaci Series

a series of numbers in which each number ( Fibonacci number ) is the sum of the two preceding numbers. The simplest is the series 1, 1, 2, 3, 5, 8, etc.



package learningJava;

import java.util.*;

public class Learnig {

public static void main(String[] args) {

int n1 = 0; int n2 = 1 ; int temp ;

System.out.print(n1 +" "+ n2+" ");

// in place of 20 just enter nth term upto which you want to print Fibonacci series

for(int i=1;i<20;i++) {

temp = n1+n2;

n1 = n2;

n2 = temp;

System.out.print(temp+ " ");

}

}

}


Output


0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765