为什么阶乘代码不起作用请告知... 变量或逻辑是否有问题?我应该改变什么?我非常感谢你的时间。非常感谢!
import java.util.Scanner;
class factorial{
public static void main(String args[])
{
System.out.println("Enter an integer to calculate its factorial");
Scanner sc = new Scanner(System.in);
String input = sc.nextLine();
int x = Integer.parseInt(input);
try {
int n = Integer.parseInt(input);
}
catch(NumberFormatException nFE) {
System.out.println("Not an Integer");
}
}
int fact(int x)
{
int result;
if(x==1)
return 1;
result = fact(x-1) * x;
int number = result;
System.out.println(fact(number));
return result;
}
}
答案 0 :(得分:0)
的System.out.println(事实(数));