public static int fact(int n) {
if (n <= 1) return 1;
return n * fact(n - 1);
}
// call: fact(5)What does fact(5) return?
- A
60
- B
24
- C
5
- Dcheck_circle
120
Explanation
5! = 5<em>4</em>3<em>2</em>1 = 120.
AP Computer Science A· difficulty 2/5
public static int fact(int n) {
if (n <= 1) return 1;
return n * fact(n - 1);
}
// call: fact(5)What does fact(5) return?
60
24
5
120
Explanation
5! = 5<em>4</em>3<em>2</em>1 = 120.
Want 10 more like this — adaptive to your weak spots?
Consider: <code class="language-java"public static int g(int n, int acc) { if (n == 0) return acc; return g(n / 2, acc + n % 2); } </code</pre What does <codeg(…
chevron_right<codepower(a, b)</code with O(log b) (using even/odd halving) is achieved by…
chevron_rightRecursive Fibonacci with memoization vs naive:…
chevron_right