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 are here to help you learn! Feel free to leave your comments and suggestions in the comment section. If you have any doubts, use the search box on the right to find answers. Thank you! 😊
«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply

Select Menu