【Java】计算1+1/2!+1/3!+1/4!....前20项
package com.company; //计算1+1/2!+1/3!+1/4!....前20项 public class Main { public static void main(String arg[]) { double sum = 0, item = 1; int i = 1, n = 20; while (i <= n) { sum += item; i++; item = item * (1.0 / i); } System.out.println("sum=" + sum); } }
本文来自博客园,作者:木子欢儿,转载请注明原文链接:https://www.cnblogs.com/HGNET/p/14584392.html