CS 2401 Quiz #4

Date: Tuesday, September 14, 2010.

Consider the following method:

  public static int test(int a, int b){
    if (a == 0) {
      return b;
    return b * 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(2, 5));

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

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