我试图计算e迭代,但我的代码给了我2.任何想法可能是错误的?因为我完全卡住了。使用循环计算e
public class iteratee {
public static void main(String[] args) {
long limit = 0;
for (int i = 0; i < 11; i++) {
limit = limit + 1/factorial(i);
}
System.out.println(limit);
}
static int factorial(int n) {
int factorial = 1;
for (int j = 1; j <= n; j++) {
factorial = factorial * j;
}
return factorial;
}
}
'limit'(我假设“e”)是一个整数类型。 int中不能有小数点。切换到“双”。 – markspace 2014-12-04 22:33:09