CS 2401 Quiz #4

Date: Wednesday, September 15, 2010.

Consider the following method:

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


















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





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