掷6面骰子6000次每个点数出现的概率
今天小编就为大家分享一篇关于掷6面骰子6000次每个点数出现的概率,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧掷6面骰子6000次每个点数出现的概率
import java.util.random;
public class statistics {
final static int maxsize = 6000;
public static void main(string[] args) {
// todo auto-generated method stub
random rand = new random();
int temp[] = new int;
for(int i = 0; i < maxsize; i++)
temp = rand.nextint(6) + 1;
int a=0, b=0, c=0, d=0, e=0, f=0;
for(int i = 0; i < temp.length; i++)
{
if(temp == 1)
a++;
else if(temp == 2)
b++;
else if(temp == 3)
c++;
else if(temp == 4)
d++;
else if(temp == 5)
e++;
else if(temp == 6)
f++;
}
system.out.println("1出现:" + a + " 2出现:" + b + " 3出现:" + c + " 4出现:" + d + " 5出现:" + e + " 6出现:" + f + "\n");
float one = (float)a/maxsize, two = (float)b/maxsize, three = (float)c/maxsize, four = (float)d/maxsize;
float five = (float)e/maxsize, six = (float)f/maxsize;
system.out.println(1 + "出现的概率是:" + one);
system.out.println(2 + "出现的概率是:" + two);
system.out.println(3 + "出现的概率是:" + three);
system.out.println(4 + "出现的概率是:" + four);
system.out.println(5 + "出现的概率是:" + five);
system.out.println(6 + "出现的概率是:" + six);
}
}
结果:
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对CodeAE代码之家的支持。如果你想了解更多相关内容请查看下面相关链接
原文链接:https://blog.csdn.net/Kingsly_Liang/article/details/79594737
http://www.zzvips.com/article/177117.html
页:
[1]