首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >计算组合函数的Java程序

计算组合函数的Java程序
EN

Stack Overflow用户
提问于 2013-10-23 04:03:43
回答 2查看 6.8K关注 0票数 1

对于我的编程类,我必须编写一个程序来计算组合函数C(n,k) =n!/(k!*(N)!)采用一种主要的输入/输出处理方法、一种计算阶乘的方法和一种计算组合函数的方法。这是我的密码:

代码语言:javascript
运行
复制
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(布尔值)方法不适用于参数(void)”。我不知道为什么会这么说。帮助?

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19532553

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档