Recursion

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(0)

What does fact(0) return?

  • A

    1

    check_circle
  • B

    stack overflow

  • C

    -1

  • D

    0

Explanation

The base case n<=1 returns 1.

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

Related questions