掷6面骰子6000次每个点数出现的概率

2025-05-29 0 83

掷6面骰子6000次每个点数出现的概率

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36
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[maxsize];

for(int i = 0; i < maxsize; i++)

temp[i] = 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[i] == 1)

a++;

else if(temp[i] == 2)

b++;

else if(temp[i] == 3)

c++;

else if(temp[i] == 4)

d++;

else if(temp[i] == 5)

e++;

else if(temp[i] == 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);

}

}

结果:

掷6面骰子6000次每个点数出现的概率

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对快网idc的支持。如果你想了解更多相关内容请查看下面相关链接

原文链接:https://blog.csdn.net/Kingsly_Liang/article/details/79594737

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 掷6面骰子6000次每个点数出现的概率 https://www.kuaiidc.com/110073.html

相关文章

发表评论
暂无评论