就是有8个数字,1,2,3,4,5,6,7,8,分别出现,现在输入大量的数据,想知道,下一个数据出现的概率,百分比每个数字是随机出现的。
下一个数就是1---8里的随机一个。
编程序统计一下每个数出现的频率,就可大概知道每个数字出现的概率。
谢谢!!!

解决方案 »

  1.   

    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 : 1110880
    2 : 1111589
    3 : 1111584
    4 : 1111386
    5 : 1111152
    6 : 1110974
    7 : 1109317
    8 : 1112621