我是一名初学者 Java 程序员,我有两个简单的文件来解决一个简单的数学问题。其中一个调用另一个,它计算数字的阶乘(例如 4!= 24)。出于某种原因,我无法调用Factorial
构造函数。
这是调用类:
package Permutations;
import Permutations.Factorial;
public class Permutations {
public static void main(String args[]) {
System.out.println("There are 10 students. Five are to be chosen and seated in a row for a picture. How many linear arrangements are possible?");
System.out.println(new Factorial(10) / new Factorial(5));
}
}
这是Factorial
课程
package Permutations;
public class Factorial {
public long Factorial(int num) {
long result = 1;
for(int i = num; i > 0; i--)
result *= i;
return result;
}
}
这是错误:
Permutations\Permutations.java:7: error: constructor Factorial in class Factoria
l cannot be applied to given types;
System.out.println(new Factorial(10) / new Factorial(5));
^
required: no arguments
found: int
reason: actual and formal argument lists differ in length
Permutations\Permutations.java:7: error: constructor Factorial in class Factoria
l cannot be applied to given types;
System.out.println(new Factorial(10) / new Factorial(5));
^
required: no arguments
found: int
reason: actual and formal argument lists differ in length
2 errors
我可以将其更改为静态方法,但是我必须使用Factorial.Factorial(num)
而不是调用它new Factorial(num)
,这会很不方便。
我不知道为什么会这样。请帮忙!
谢谢。
编辑
感谢您的回答。我已经弄清楚我做错了什么。