Introduction to Java Programming编程题6.7<统计0~9随机数出现的次数>
来源:互联网 发布:淘宝网怎么举报卖家 编辑:程序博客网 时间:2024/06/03 12:48
建立一个大小为10的int数组,例如随机出现的数字为5则将下标为5的数字加1.
/*The random digits:--------------------------------2 5 9 9 1 9 2 7 0 19 2 4 2 7 5 4 5 6 12 4 7 8 1 7 6 8 2 95 5 9 9 2 5 2 2 5 66 9 2 2 1 9 6 2 1 32 3 5 0 6 4 1 2 1 78 3 5 2 8 9 5 9 8 98 8 8 0 0 3 0 2 5 83 3 7 8 2 3 6 3 9 44 6 5 9 8 5 2 2 6 60 ~ 9 ocurr times:--------------------------------0 occur times:51 occur times:82 occur times:193 occur times:84 occur times:65 occur times:136 occur times:107 occur times:68 occur times:119 occur times:14 */public class CountDigitOccur { public static void main(String[] args) { final int SIZE = 10; final int MAX_SIZE = 100; int[] counts = new int[SIZE]; System.out.println("The random digits:"); System.out.println("--------------------------------"); for (int i = 0; i < MAX_SIZE; i++) { int digits = (int)(Math.random() * 10); System.out.print(digits + " "); if ((i + 1) % 10 == 0) System.out.println(); counts[digits]++; } System.out.println("\n0 ~ 9 ocurr times:"); System.out.println("--------------------------------"); showCounts(counts); } public static void showCounts(int[] pr) { for (int i = 0; i < pr.length; i++) System.out.println(i + " occur times:" + pr[i]); }}
0 0
- Introduction to Java Programming编程题6.7<统计0~9随机数出现的次数>
- Introduction to Java Programming编程题6.3<计算数字的出现次数>
- Introduction to Java Programming编程题9.4<求某个字符的出现次数>
- Introduction to Java Programming编程题5.32<赢取双骰子游戏的次数>
- Introduction to Java Programming编程题9.6<统计字符串中字母的个数>
- Introduction to Java Programming编程题9.5<统计字符串中数字的个数>
- Introduction to Java Programming编程题9.17<统计文件行、字符、单词数>
- Java-10-50的随机数,统计出现的次数
- introduction to Java Programming 编程题5.3<回文整数>
- Introduction to Java Programming编程题5.6<打印数字三角形>
- Introduction to Java Programming编程题5.13<数列求和>
- Introduction to Java Programming编程题5.14<计算数列>
- Introduction to Java Programming编程题5.17<01矩阵>
- Introduction to Java Programming编程题5.26<回文素数>
- Introduction to Java Programming编程题5.27<反素数>
- Introduction to Java Programming编程题5.29<掷骰子游戏>
- Introduction to Java Programming编程题5.28<梅森素数>
- Introduction to Java Programming编程题5.30<双素数>
- 数据结构 C语言实现希尔排序
- HDU 1253 胜利大逃亡 【BFS模板题】
- java中的final关键字
- 最全的orcal-sql笔记
- Avro Rpc
- Introduction to Java Programming编程题6.7<统计0~9随机数出现的次数>
- codeforces 311(div2)C-Arthur and Table
- C++ Primer : 第十一章 : 关联容器之概述、有序关联容器关键字要求和pair类型
- Hadoop源码---Inputformat
- 文章标题
- Java中的抽象类
- WXHL 学习总结连载(六)
- C# 事件驱动基础
- 什么是JS事件冒泡?