擲6面骰子6000次每個點數(shù)出現(xiàn)的概率
更新時間:2019年02月27日 16:33:10 作者:Kingsly_Liang
今天小編就為大家分享一篇關于擲6面骰子6000次每個點數(shù)出現(xiàn)的概率,小編覺得內容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
擲6面骰子6000次每個點數(shù)出現(xiàn)的概率
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出現(xiàn):" + a + " 2出現(xiàn):" + b + " 3出現(xiàn):" + c + " 4出現(xiàn):" + d + " 5出現(xiàn):" + e + " 6出現(xiàn):" + 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 + "出現(xiàn)的概率是:" + one);
System.out.println(2 + "出現(xiàn)的概率是:" + two);
System.out.println(3 + "出現(xiàn)的概率是:" + three);
System.out.println(4 + "出現(xiàn)的概率是:" + four);
System.out.println(5 + "出現(xiàn)的概率是:" + five);
System.out.println(6 + "出現(xiàn)的概率是:" + six);
}
}
結果:

總結
以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對腳本之家的支持。如果你想了解更多相關內容請查看下面相關鏈接
相關文章
老生常談Java中List與ArrayList的區(qū)別
大家都知道List是接口,ArrayList是List接口的一個實現(xiàn)類,接下來通過本文給大家介紹Java中List與ArrayList的區(qū)別,需要的朋友可以參考下2022-08-08
詳解SpringBoot中異步請求和異步調用(看完這一篇就夠了)
這篇文章主要介紹了SpringBoot中異步請求和異步調用問題,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下2019-04-04
java階乘計算獲得結果末尾0的個數(shù)代碼實現(xiàn)
今天偶然看到一個要求,求1000~10000之間的數(shù)n的階乘并計算所得的數(shù)n!末尾有多少個0?要求: 不計算 只要得到末尾有多少個0就可以了,看下面的代碼吧2013-12-12
Springmvc DispatcherServlet原理及用法解析
這篇文章主要介紹了Springmvc DispatcherServlet原理及用法解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2020-09-09
SpringBoot+MyBatis-Plus實現(xiàn)數(shù)據(jù)庫讀寫分離的代碼示例
在當今互聯(lián)網(wǎng)應用中,數(shù)據(jù)庫讀寫分離是提高系統(tǒng)性能和穩(wěn)定性的重要手段之一,通過將讀操作和寫操作分別路由到不同的數(shù)據(jù)庫節(jié)點,可以有效減輕數(shù)據(jù)庫服務器的負擔,本文將介紹如何利用SpringBoot和MyBatis-Plus框架實現(xiàn)數(shù)據(jù)庫讀寫分離,需要的朋友可以參考下2023-11-11

