8个数字,1,2,3,4,5,6,7,8,分别出现,现在输入大量的数据,想知道,下一个数据出现的概率,百分比。。。 就是有8个数字,1,2,3,4,5,6,7,8,分别出现,现在输入大量的数据,想知道,下一个数据出现的概率,百分比每个数字是随机出现的。下一个数就是1---8里的随机一个。编程序统计一下每个数出现的频率,就可大概知道每个数字出现的概率。谢谢!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import java.util.Random;public class NewClass { public static void main(String[] args) { int count = 10000000; int[] frequency = new int[9]; Random rand = new Random(System.nanoTime()); int index = 0; for (int i = 0; i < count; ++i) { index = rand.nextInt(9); frequency[index] = frequency[index] + 1; } for (int i = 1; i < frequency.length; ++i) { System.out.println(i + " : " + frequency[i]); } }}输出:1 : 11108802 : 11115893 : 11115844 : 11113865 : 11111526 : 11109747 : 11093178 : 1112621 java处理visio的问题 nextLine循环输入问题 如何用键盘控制panel的焦点的移动 System.out.println("aaa 88888c".matches(".{3}\\b\\d{5}.")); 看看这个正则表达式问题在哪里? 查一查原因! Unhandled Exception thrown: class java.lang.NullPointerException 救命啊!!! JForum怎么在框架外部获取SimpleHash 怎么样才能打开一个JPG文件 Applet中可以写服务器上的文件吗? Jtable 表格选择一行时触发事件 如何学会 用Java API?
int count = 10000000;
int[] frequency = new int[9];
Random rand = new Random(System.nanoTime()); int index = 0;
for (int i = 0; i < count; ++i) {
index = rand.nextInt(9);
frequency[index] = frequency[index] + 1;
} for (int i = 1; i < frequency.length; ++i) {
System.out.println(i + " : " + frequency[i]);
}
}
}输出:
1 : 1110880
2 : 1111589
3 : 1111584
4 : 1111386
5 : 1111152
6 : 1110974
7 : 1109317
8 : 1112621