public static int pow(int b, int e) {
if (e == 0) return 1;
return b * pow(b, e - 1);
}
// call: pow(2, 5)What does pow(2,5) return?
- A
10
- B
25
- C
16
- Dcheck_circle
32
Explanation
2^5 = 32.
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(2, 5)What does pow(2,5) return?
10
25
16
32
Explanation
2^5 = 32.
Want 10 more like this — adaptive to your weak spots?
The figure shows the call tree for naive <codefib(4)</code. Notice that…
chevron_rightWhat is printed?…
chevron_rightConsider: <code class="language-java"public static String r(String s) { if (s.length() <= 1) return s; return r(s.substring(1)) + s.charAt(0); } </code</pre Wha…
chevron_right