作业帮 > 综合 > 作业

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

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/13 19:46:19
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