/** * Created by Casper on 08-12-2015. */ public class FibIter { private static long fib_iter(long a) { long r = 0; long minus_one = 1; long minus_two = 0; if (a == 0) { r = 0; } else if (a == 1) { r = 1; } else { for (long i = 2; i <= a; i++) { r = minus_one + minus_two; minus_two = minus_one; minus_one = r; } } return r; } public static void main(String[] args) { long a = 0; long r = 0; a = Long.parseUnsignedLong(args[0]); r = fib_iter(a); System.out.println("fib(" + Long.toUnsignedString(a) + ") = " + r); } }