CS 2401 Quiz #5

Date: Tuesday, February 23, 2010.

1. Consider the following program:

import java.util.*;

public class quiz5 {

    static Vector trace = new Vector();

   public static void main(String[] args)
      {
       fib(2, 3, 5);
       System.out.println(trace);
      }

   public static int fib(int a, int b, int n)
      {

        if (n == 1)
              return a;

        else if (n == 2)
             return b;
        else
        {
            int x = fib(a, b, n - 1) + fib(a, b, n - 2);
            trace.insertElementAt(x, 0);
            return x;
        }

      }
}
Is the program above going to execute successfully or crash?

1b.