Recursion

AP Computer Science A· difficulty 2/5

public static int pow(int b, int e) {
  if (e == 0) return 1;
  return b * pow(b, e - 1);
}
// call: pow(7, 0)

What is the result?

  • A

    1

    check_circle
  • B

    7

  • C

    0

  • D

    infinite recursion

Explanation

The base case returns 1 for any exponent of 0.

Want 10 more like this — adaptive to your weak spots?

Related questions