【发布时间】:2018-02-27 21:15:49
【问题描述】:
问题:单掷 2 个公平(均匀加权)骰子,求每个骰子掷出的点数不同且总和为 6 的概率。
我的代码有什么问题 最后 3 个打印语句不起作用
public class Test{
public static void main(String[] args){
System.out.println("Enter");
int count=0;
int deno=36;
for(int i=1; i<7; i++){
for(int j=1; i<7; j++){
if((i+j)==6 && i!=j){
count++;
}
}
}
for(int i = 2; i<=10; i++){
if(count%i==0 && deno%i==0){
count=count/i;
deno=deno/i;
}
}
System.out.println(count);
System.out.println("/");
System.out.println(deno);
}
}
【问题讨论】:
-
错字导致无限循环 -
for(int j=1; i<7; j++){->for(int j=1; j<7; j++){ -
最后 3 个打印输出语句在控制台上没有给出任何 noutput
-
请贴出修改后的代码
-
谢谢你的朋友,非常感谢你
标签: java probability