class Test_08 {
public static void main(String[] args) {
long result = 0;
for (int i = 1; i <= 20; i++) {
long mul = 1;
for (int j = 1; j <= i; j++) {
mul *= j;
}
result += mul;
}
System.out.println("1!+2!+3!+4!+5!+。。。。+20!=" +result);
}
}
第二种做法:
class Test_08 {
public static void main(String[] args) {
long i;
long j = 1;
long sum = 0;
for (i = 1;i <= 20;i++) {
j = j * i;
sum = sum + j;
}
System.out.println(sum);
}