Java find the approximate value of e using 2+(2!)^-1+(3!)^-1+(4!)^-1+...
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/15 01:51:46
Javafindtheapproximatevalueofeusing2+(2!)^-1+(3!)^-1+(4!)^-1+...Javafindtheapproximatevalueofeusing2
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