// // (Naively) Compute Fibonacci numbers. // // Warning: fibonacci(60) will take days to compute! // public class Fibonacci { public static long fib(long n) { if ( n <= 1 ) return 1; else return fib(n -1 ) + fib(n - 2); } public static void main(String[] args) { if ( args.length != 1 ) throw new IllegalArgumentException("Usage: java Fibonacci number"); long number; try { number = Long.parseLong(args[0]); } catch ( NumberFormatException e ) { throw new IllegalArgumentException("Usage: java Fibonacci number\n " + args[0] + " is not a number."); } long result = fib(number); java.text.NumberFormat withCommas = java.text.NumberFormat.getInstance(); withCommas.setGroupingUsed(true); System.out.println("Fib of " + number + " is " + withCommas.format(result)); } }