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); } }