用JAVA语言编程 求1!+2!+3!+4!+5!+6!+7!+8!+9!+10!。(要求:使用while、do-while、for三种语句

1!+2!+3!+4!+5!+6!+7!+8!+9!+10!是什么意思?

1!:表示1的阶乘;
2!表示2的阶乘,就是1*2
依次类推就行。
1!+2!+3!+4!+5!+6!+7!+8!+9!+10!就是求和嘛,这个直接用循环求和就行了。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-03-28
public class Test{
public static void main(String[] args){
int x = 1; //用于求每个数的阶层
int count = 0,sum = 0; //用于统计1 - 10 阶层的和
int[] m = new int[10]; //用于保存每个阶层的结果,可以自己去打印
//对于这里,没什么好解释的,你自己带值手动跑2次,就知道是什么意思了。
for(int i = 1; i <= 10; i++){
x = count + x * i;
count = x;
m[i] = count;
sum = sum + count;
}
System.out.println("count = " + count);
}
}本回答被提问者采纳
第2个回答  2011-03-28
public class Test{
public static void main(String[] args){
int x = 1; //用于求每个数的阶层
int count = 0,sum = 0; //用于统计1 - 10 阶层的和
int[] m = new int[11]; //用于保存每个阶层的结果,可以自己去打印
//对于这里,没什么好解释的,你自己带值手动跑2次,就知道是什么意思了。
for(int i = 1; i <=10; i++){
x = count + x * i;
count = x;
m[i] = count;
sum = sum + count;
}
System.out.println("count = " + count);
}
}
//二楼数组下标越界
第3个回答  2011-03-28
写个for循环的吧,其他的一个道理
int total = 0;
for (int i = 1; i <= 10; i++) {
total += i * i;
}
System.out.println(total);

擦,算成平方值了。。。 楼上正解。