递归的问题
package com.hx.test;
public class Test {
public Test() {
}
public int f(int n) {
if (n == 0) {
return 1;
}
return n * f(n - 1);
}
public static void main(String[] args) {
Test test = new Test();
int result = test.f(20);
System.out.println("result = " + result);
}
}
为什么结果是:result = -2102132736
是一个负数
如果将test.f(20)中的20改为10的话,运算的结果是正数