JAVA實例:求1+2!+3!+...+20!的和
程序分析:此程序只是把累加變成了累乘
public class Ex21 {
staticlongsum = 0;
staticlongfac = 0;
publicstaticvoid main(String[] args) {
long sum = 0; long fac = 1; for(int i=1; i<=10; i++) { fac = fac * i; sum += fac; } System.out.println(sum); } } *