生日问题 - N 中至少有 2 个

The Birthday Problem - at least 2 out of N

我收到了一点修改后的生日问题- 我需要 运行 一个函数,该函数 returns N 个人中至少有两人生日相同的概率。然后一个 计算最小 n 的主函数,使得该概率至少为 0.5。 我试着写一个,但唯一的输出是 0 或 1,我将不胜感激调试或指出我做错了什么。 这是我所做的:

public class Birthday {

    public static double probSameBirthday(int n) {
        double days = 1 / 365;   // number of days
        int i, person = 0;       // total number of people
        double noProb = 0;
        int people = n;

        for (i = 2; i <= n; i = i + 1) {
            person = i;
            noProb = (1 - ( noProb * (1 - (person - 1) * days))) / 100;
        }

        return (noProb);        
    }

    public static void main(String[] args){
        int n = Integer.parseInt(args[0]);
        System.out.println(probSameBirthday(n));
    }
}

回复感谢评论: 将天数更改为

double days = 1.0 / 365.0;

 the noProb =(1-( noProb * (1- (person-1)*days)))/100;

noProb =( noProb * (1- (person-1)*days));

和 return 到 return (1-noProb); 它现在与 https://www.dcode.fr/birthday-problem

中的计算器一样运行