CS 2401 Quiz #4

Date: Tuesday, March 1, 2011.

Consider the following method:

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

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(3, 1));

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.