1
package com.poi.importxls;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
//从(0,1)中平均随机出几次才能使得和超过1?(e)
public class Times {
public static void main(String[] args) {
Random random = new Random();
List<Double> dlDoubles = new ArrayList<Double>();
double all = 0.0;
int loop =10000000;
for (int j = 0; j < loop; j++) {
double d = 0;
boolean flg =true;
int i = 0;
while(flg)
{
d +=random.nextDouble();
i++;
if(d>1)
{
dlDoubles.add(new Double(i));
all +=i;
flg = false;
}
}
}
System.out.println(all/loop);
}
}
2.7183916
结果正好为e 好神奇啊