/* File: Fib.java - March 2015 */ package l04; /** * Compute and display the Fibonacci number of the input argument using * a somewhat subtle recursive approach. * * @author Michael Albert * */ public class Fib{ public static void main(String[] args) { int n = Integer.parseInt(args[0]); System.out.println("Fib(" + n + ") = " + fib(n)); } public static long fib(int n) { return fib(0L, 1L, n); } public static long fib(long prev, long curr, int n) { if (n == 0) return curr; return fib(curr, prev+curr, n-1); } }