CS 2401 Quiz #4

Date: Monday, February 28, 2011.

Consider the following method:

  public static int test(int a, int b){
    if (b == 0) {
      return a;
    }
    return b + test(a, b - 1);
  }

1. Trace the execution of the following statement:

Reminder: Your trace should show successive calls to the method. For each call, the trace should include the values of the parameters and the value returned to the caller.

  System.out.println(test(5, 2));















2. In one sentence, describe what would happen if the following statement was executed:
  System.out.println(test(3, -1));




4. For extra credit: Write down the exact function computed by method "test" in terms of a and b.