1!加到10!,用java怎么表达?

2024-11-17 15:42:26
推荐回答(1个)
回答1:

参考源代码:

public class Test {

public static void main(String[] args) {

int f = 1;

int sum = 0;

int n = 10;


for(int i=1; i<=n; i++) {

f *= i;

sum += f;

}


System.out.println("1!+2!+...+" + n + "! = " + sum);

}

}



运行结果: