- public static void main(String[] args)
- {
- //String[] str = new String[]{"20%","10%","30%","15%","25%"};
- int i = 0;
- double[] f = new double[5];
- double[] count = new double[5];
- while(true)
- {
- i = (int) (Math.random()*5);
- System.out.println(i);
- switch(i)
- {
- case 0:
- {
- count[0]++;
- break;
- }
- case 1:
- {
- count[1]++;
- break;
- }
- case 2:
- {
- count[2]++;
- break;
- }
- case 3:
- {
- count[3]++;
- break;
- }
- case 4:
- {
- count[4]++;
- break;
- }
- }
- if(count[0]+count[1]+count[2]+count[3]+count[4] > 10000)
- {
- break;
- }
- }
- f[0] = count[0]/(count[0]+count[1]+count[2]+count[3]+count[4]);
- f[1] = count[1]/(count[0]+count[1]+count[2]+count[3]+count[4]);
- f[2] = count[2]/(count[0]+count[1]+count[2]+count[3]+count[4]);
- f[3] = count[3]/(count[0]+count[1]+count[2]+count[3]+count[4]);
- f[4] = count[4]/(count[0]+count[1]+count[2]+count[3]+count[4]);
- System.out.println(f[0]+","+f[1]+","+f[2]+","+f[3]+","+f[4]);
- }
复制代码
|
|