public class Fibonacci { public static void main (String[] argv) { // Test case 1: int n = 5; int f = fibonacci (n); System.out.println ("f(" + n + ") = " + f); // Test case 2: n = 20; f = fibonacci (n); System.out.println ("f(" + n + ") = " + f); } static int fibonacci (int n) { // Base cases: if (n == 1) { return 0; } else if (n == 2) { return 1; } // f_n = f_{n-1} + f_{n-2} int f_n_minus_one = fibonacci (n-1); int f_n_minus_two = fibonacci (n-2); return f_n_minus_one + f_n_minus_two; } }