File size: 385 Bytes
e49b994
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package com.sxt;

public class text {
	public static void main(String[] args) {
		int n = 20; 
		double sum = 1.0;
		double term; 
		double factorial = 1; 
		
		for (int i = 1; i <= n; i++) {
			factorial *= i; 
			term = 1.0 / factorial;
			sum += term;                     
			if (term < 0.0001) {
				break;
			}
		}
		System.out.printf("%.4f", sum, args);
	}
}