previous | start | next

Recursive Example

      F(0) = 0
      F(1) = 1
      F(N) = F(N - 1) + F(N - 2) if N > 1.
   

In java:

    1   
    2   public class Fibonacci {
    3     public static int F (int N) {
    4       if (N == 0) return 0;
    5       if (N == 1) return 1;
    6       return F (N - 1) + F (N - 2);
    7     }
    8   
    9     public static void main (String[] args) {
   10       for (int N = 0; N < 25; N++) {
   11           System.out..println (N + " " + F(N));
   12       }
   13     }
   14   }


previous | start | next