Java find the approximate value of e using 2+(2!)^-1+(3!)^-1+(4!)^-1+...

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/30 08:01:59
Java find the approximate value of e using 2+(2!)^-1+(3!)^-1+(4!)^-1+...

Java find the approximate value of e using 2+(2!)^-1+(3!)^-1+(4!)^-1+...
Java find the approximate value of e using 2+(2!)^-1+(3!)^-1+(4!)^-1+...

Java find the approximate value of e using 2+(2!)^-1+(3!)^-1+(4!)^-1+...
OK.I'll see it today
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
//2+(2!)^-1+(3!)^-1+(4!)^-1+...
System.out.print("Please input a digit number n:");
int n = new Scanner(System.in).nextInt();
double sum = calcSum(n);
System.out.println(sum);
}
private static double calcSum(int n) {
int i = 2;
long fac = 1L;
double sum = 2;
while(i