递归调用将在运行时堆栈上构建,然后在运行时堆栈“展开”时以相反的顺序计算值。第18行是我收到错误的地方,但我对于错误的描述是空白的。编译完成。以下文件未编译: 找到1个错误: [line:18]} else { 错误:'否则'没有'如果'
public class Recursion {
public static void main(String[] args) {
int n = 7;
//Test out the factorial
System.out.println(n + " factorial equals ");
System.out.println(Recursion.factorial(n));
System.out.println();
}
public static int factorial(int n) {
int temp;
System.out.println("Method call -- calculating Factorial of: " + n);
{
int temp;
if (n == 0) {
return 1;
}
} else {
temp = factorial(n - 1);
System.out.println("Factorial of: " + (n - 1) + " is " + temp);
return (temp * n);
}
}
}