1. package com.instaceofjava;

    public class Fibanaciwithoutrecursive {

    public static void main(String[] args) {

    int n1=0;

    int n2=1;

    System.out.println(n1);

    System.out.println(n2);

    for(int i=0;i<=100;i++){

    int sum=n1+n2;

    if(sum<=100){

    n1=n2;

    n2=sum;

    System.out.println(sum);

    }
    }
    }




  1. Output:
    0
    1
    1
    2
    3
    5
    8
    13
    21
    34
    55
    89






Instance Of Java

We will help you in learning.Please leave your comments and suggestions in comment section. if you any doubts please use search box provided right side. Search there for answers thank you.
«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply

Select Menu