import acm.program.*;
import acm.util.*;
public class execrise604 extends ConsoleProgram {
/**
*
*/
private static final long serialVersionUID = 1L;
private static final int 样本个数 = 10000;
public void run(){
int i = 样本个数;
int y = 0;
while (i > 0){
int j = 0;
for (int h = 0; h < i; h++){
if (rgen.nextBoolean()){
i--;
j++;
}
}
y++;
println("第" + y + "年有" + j + "个原子衰减!还剩余:" + i);
}
}
private RandomGenerator rgen = RandomGenerator.getInstance();
}
从理论上讲,每年衰减应该是剩余数的一半左右,可我怎么运行,每年衰减都是剩余数的三分之一左右。
import acm.util.*;
public class execrise604 extends ConsoleProgram {
/**
*
*/
private static final long serialVersionUID = 1L;
private static final int 样本个数 = 10000;
public void run(){
int i = 样本个数;
int y = 0;
while (i > 0){
int j = 0;
for (int h = 0; h < i; h++){
if (rgen.nextBoolean()){
i--;
j++;
}
}
y++;
println("第" + y + "年有" + j + "个原子衰减!还剩余:" + i);
}
}
private RandomGenerator rgen = RandomGenerator.getInstance();
}
从理论上讲,每年衰减应该是剩余数的一半左右,可我怎么运行,每年衰减都是剩余数的三分之一左右。