package com.naughtyzombie.fib;

/**
 * Created by pram on 22/06/2015.
 */
public class FibonnaciLoop {
    public static void main(String[] args) {
        int n = 25, first = 0, second = 1, next, i;
        System.out.println("Printing first " + n + " numbers in Fibonacci Series \n");
        calc(n, first, second);
    }

    private static void calc(int n, int first, int second) {
        int i;
        int next;
        for (i = 0; i < n; i++) {
            if (i <= 1)
                next = i;
            else {
                next = first + second;
                first = second;
                second = next;
            }
            System.out.print(next + "\t");
        }
    }
}

@@ -691,10 +691,446 @@
 %7D%0A    %7D%0A
+    %0A    //This implementation works in all cases%0A    public int getFib(int nthNum) %7B%0A        int next = 0;%0A        int first = 0;%0A        int second = 1;%0A%0A        if (nthNum %3C 2) %7B%0A            next = nthNum;%0A        %7D else %7B%0A            for (int i = 2; i %3C= nthNum; i++) %7B%0A                next = first + second;%0A                first = second;%0A                second = next;%0A            %7D%0A        %7D%0A        %0A        return next;%0A    %7D%0A
 %7D%0A

Update FibonnaciLoop.java