This is a simple program, compiled with Sun's javac, no optimisation.

Here is the original Java source code:

import java.lang.*;

class Fibo {
    private static int fib (int x) {
        if (x > 1)
            return (fib(x - 1) + fib(x - 2));
        else return (x);
    }

    public static void main(String args[]) throws Exception {
    int number = 0, value;

        try {
            number = Integer.parseInt(args[0]);
        } catch (Exception e) {
            System.out.println ("Input error");
            System.exit (1);
        }
        value = fib(number);
        System.out.println ("fibonacci(" + number + ") = " + value);
    }

}
You use the program like this:
% java Fibo 10
fibonacci(10) = 55
%

-- MikeVanEmmerik - 13 Feb 2003

Revision: r1.2 - 13 Feb 2003 - 22:17 - MikeVanEmmerik
Copyright © 1999-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback