01: import javax.swing.JOptionPane;
02: 
03: /**
04:    This program computes Fibonacci numbers using a recursive
05:    method.
06: */ 
07: public class FibTest
08: {  
09:    public static void main(String[] args)
10:    {  
11:       String input = JOptionPane.showInputDialog("Enter n: ");
12:       int n = Integer.parseInt(input);
13: 
14:       for (int i = 1; i <= n; i++)
15:       {
16:          int f = fib(i);
17:          System.out.println("fib(" + i + ") = " + f);
18:       }
19:       System.exit(0);
20:    }
21: 
22:    /**
23:       Computes a Fibonacci number.
24:       @param n an integer
25:       @return the nth Fibonacci number
26:    */
27:    public static int fib(int n)
28:    {  
29:       if (n <= 2) return 1;
30:       else return fib(n - 1) + fib(n - 2);
31:    }
32: }