qiu!!1
java编程求:1!+2!+3!+……+10!
------解决方案--------------------public class Sum {
public static void main(String args[]) {
int sum = 0;
int a = 1;
for (int i = 1; i <= 10; i++) {
a = a * i;
sum = sum + a;
}
System.out.println("sum= " + sum);
}
}
------解决方案--------------------
long result=0;
for(long i = 1;i<=10;i++){
long k = 1;
for(long j=1;j<=i;j++){
k*= j;
}
result += k;
}
System.out.println(result);