Recursion

AP Computer Science A· difficulty 4/5

<code>power(a, b)</code> recursively:

  • A

    return Math.pow(a, b);

  • B

    if (b == 0) return 1; else return a * power(a, b - 1);

    check_circle
  • C

    while (b > 0) ...

  • D

    for-each

Explanation

a^0 = 1; a^b = a · a^(b-1).

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

Related questions