服务器之家:专注于VPS、云服务器配置技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - Java教程 - 掷6面骰子6000次每个点数出现的概率

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

2021-07-17 12:33Kingsly_Liang Java教程

今天小编就为大家分享一篇关于掷6面骰子6000次每个点数出现的概率,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧

掷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次每个点数出现的概率

总结

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

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

延伸 · 阅读

精彩推荐