对于我的编程课,我必须编写一个程序,通过使用处理输入/输出的主要方法来计算组合函数 C(n,k) = n!/(k!*(nk)!),这是一种计算方法阶乘,以及计算组合函数的方法。这是我的代码:
import java.util.Scanner;
public class Combinations {
public static void factorials (int set, int objects) {
Scanner keyboard = new Scanner(System.in);
int n = set;
int k = objects;
int c = (n-k);
int factorial1 = 1;
int factorial2 = 1;
int factorial3 = 1;
while (n > 0) {
factorial1 = factorial1 + s;
n = n++;
}//while loop
while (k > 0) {
factorial2 = factorial2 + o;
k = k++;
}//while loop
while (c > 0) {
factorial3 = factorial3 + c;
c = c++;
}//while loop
System.out.println(Combinations(factorial1,factorial2,factorial3));
}//method factorials
public static int Combinations (int set, int objects, int x){
int n = set;
int k = objects;
int c = x;
int combination;
combination = n/(k*c);
return combination;
}//method Combinations
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter the number of integers in a set: ");
int n = keyboard.nextInt();
System.out.println("Enter the number of objects to be chosen from the set: ");
int k = keyboard.nextInt();
System.out.println(factorials(n,k));
}//method main
}//class
我的问题是我收到一条错误消息System.out.println(factorials(s,o));
- “类型 PrintStream 中的方法 println(boolean) 不适用于参数 (void)”。我不知道它为什么这么说。帮助?