Rajat Malakar Pages

Monday, 22 July 2013

Using While loop Find the Fibonacci series in Java.

// Rajat Malakar


import java.util.*;

public class Fibonacci {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int prev, next, sum, n = 1, count;
        System.out.println("Enter number upto which Fibonacci series to print: ");
        count = sc.nextInt();
        prev = next = 1;
        System.out.println(">>>>>> : Fibonacci Series : <<<<<<");
        while (n <= count) {
            System.out.println(prev);
            sum = prev + next;
            prev = next;
            next = sum;
            n++;
        }
    }
}

5 comments:

  1. Sir,
    How to print the same Fibonacci series in reverse order

    ReplyDelete
  2. Sir,
    How to print the same Fibonacci series in reverse order

    ReplyDelete
  3. can u dry run this programme

    ReplyDelete
  4. Very good! Thank you. Happiness.

    ReplyDelete

Thanks for Your Comment.

satta king 786