博客
关于我
模拟T次投掷骰子
阅读量:162 次
发布时间:2019-02-28

本文共 864 字,大约阅读时间需要 2 分钟。

模拟投掷骰子

代码

package Rolls;import Counter.Counter;import common.StdOut;import common.StdRandom;/** Copyright (C), 2020-2020, XXX有限公司 * FileName: Rolls * Author:   cakin * Date:     2020/1/11 * Description: 模拟投掷骰子 */public class Rolls {    public static void main(String[] args) {        int T = Integer.parseInt(args[0]);        int SIDES = 6;        Counter[] rolls = new Counter[SIDES + 1];        for (int i = 1; i <= SIDES; i++) {            rolls[i] = new Counter(i + "'s");        }        for (int t = 0; t < T; t++) {            int random = StdRandom.nextInt(SIDES) + 1;            rolls[random].incrementCount();        }        // 输出结果        for (int i = 1; i <= SIDES; i++) {            StdOut.println(i + "'s count: " + rolls[i].getCount());        }    }}

测试结果

当投掷1000000次的结果如下:

166995 1's166249 2's166429 3's167018 4's166639 5's166670 6's

代码参考

// 代码参考

转载地址:http://efqj.baihongyu.com/

你可能感兴趣的文章
R&Python Data Science 系列:数据处理(2)
查看>>
php递归算法总结
查看>>
PHP递归遍历文件夹
查看>>
R&Python Data Science 系列:数据处理(1)
查看>>
php错误日志文件
查看>>
PHP错误解决:Array and string offset access syntax with curly braces is deprecated
查看>>
php隐藏手机号中间4位方法总结
查看>>
php面向对象三大特征封装、多态、继承
查看>>
php面向对象全攻略
查看>>
php面向对象的基础题
查看>>
php面试题二--解决网站大流量高并发方案(从url到硬盘来解决高并发方案总结)...
查看>>
php页面增加自选项,php-在Woocommerce中添加新的自定义默认订购目录选项
查看>>
php页面静态化技术;学习笔记
查看>>
php项目心得以及总结
查看>>
R&Python Data Science 系列:数据处理(4)长宽格式数据转换
查看>>
PHP项目集成支付宝PC端扫码支付API(国内支付)
查看>>
php预定义常量&变量
查看>>
R 集成算法③ 随机森林
查看>>
php验证码背景色设置无效
查看>>
php验证邮箱是否有效
查看>>