【发布时间】:2020-03-12 18:46:50
【问题描述】:
我必须编写一个程序来计算中奖概率 以奥地利系统计算(45 个中有 6 个)。
我使用这个公式:45!/6!*39! = 45 *44*43*42*41*40/1*2*3*4*5*6(因为数字被缩短了)。但计算不正确,程序给出2179827 作为答案而不是8415060。有人可以帮我告诉我错误在哪里吗?
package homework_1;
public class Aufgabe_3 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int n = 45*44*43*42*41*40;
int m = 1*2*3*4*5*6;
int w = n/m;
System.out.println("Die Wahrscheinlichkeit ist: " + w);
}
}
提前非常感谢您! :)
【问题讨论】:
-
45 * 44 * 43 * 42 * 41 * 40 = 5864443200 > 2147483648 = 2^31 = Integer.maxValue() -
备注:程序计算的不是概率(Wahrscheinlichkeit),而是唯一事件的数量。概率是倒数(因为这是一个相等的分布)。
标签: java calculation