【发布时间】:2019-03-10 14:14:48
【问题描述】:
创建两个单独的包数学和应用程序。在任一类中都有一个名为 MathHelper 和 Application 的类。我需要将静态方法添加到名为 factorial(int) 的 MathHelper.java 类中,该类接收一个整数并返回传递的数字的阶乘。一个 main 方法被添加到应用程序并调用 Mathhelper.factorial。这是我到目前为止的代码......
public class Application {
public static void main(String[]args) {
System.out.println(MathHelper.doubleInt((9)));
}
}
public class MathHelper {
public static void main(String[]args) {
}
public static int fact(int factNum) {
if (factNum==1) {
return 1;
}
else {
return factNum + (fact(factNum - 1));
}
}
}
【问题讨论】:
-
我认为这是正确的总体思路,但
+必须是*- 阶乘意味着将大量数字相乘,而不是相加。