掷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);
}
}
|
结果:
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对服务器之家的支持。如果你想了解更多相关内容请查看下面相关链接
原文链接:https://blog.csdn.net/Kingsly_Liang/article/details/79594737