用while语句计算e≈1+1/1!+1/2!+…+1/n!
时间: 2024-01-29 19:02:02 浏览: 181
1!+2!+..n!
以下是使用while语句计算e≈1+1/1!+1/2!+…+1/n!的代码:
```java
public class Main {
public static void main(String[] args) {
int n = 10;
double e = 1.0;
int i = 1;
int factorial = 1;
while (i <= n) {
factorial *= i;
e += 1.0 / factorial;
i++;
}
System.out.println("e ≈ " + e);
}
}
```
阅读全文