Complete the code to return 1 when n is 0 in the factorial function.
if (n == 0) { return [1]; }
The factorial of 0 is defined as 1, so the function should return 1 when n is 0.
Complete the recursive call to calculate factorial of n.
return n * factorial([1]);
The factorial function calls itself with n - 1 to reduce the problem size until it reaches 0.
Fix the error in the method signature to correctly define the factorial function.
public static [1] factorial(int n) {The factorial function returns an integer value, so the return type should be int.
Fill both blanks to complete the factorial function with base case and recursive call.
if (n == 0) { return [1]; } else { return n * factorial([2]); }
The base case returns 1 when n is 0, and the recursive call uses n - 1.
Fill all three blanks to create a complete factorial method with correct signature, base case, and recursive call.
public static [1] factorial(int n) { if (n == 0) { return [2]; } else { return n * factorial([3]); } }
The method returns int, base case returns 1, and recursive call uses n - 1.
