是越界了,你那个数儿太大了,像下面这样就可以了
public class factorialTest{
static double factorial(int arg){
if(arg==0){
return 1;
}
else{
return arg*factorial(arg-1);
}
}
public static void main(String[] args){
System.out.println(factorial(0));
System.out.println(factorial(1));
System.out.println(factorial(2));
System.out.println(factorial(20));
System.out.println(factorial(50));
}
}
运行结果:
1.0
1.0
2.0
2.43290200817664E18
3.0414093201713376E64 |