为网友们分享了相关的编程文章,网友万俊远根据主题投稿了本篇教程内容,涉及到java、掷骰子概率代码、掷6面骰子6000次每个点数出现的概率相关内容,已被435网友关注,下面的电子资料对本篇知识点有更加详尽的解释。
掷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[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); } }
结果:
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对码农之家的支持。如果你想了解更多相关内容请查看下面相关链接