用java语言求出 result = 1!+2!+3!+4!+5!+6!+7!+8!+9!+10!(阶层)的和,拜托各位大哥大姐了

 我来答
百度网友77b129d416d
2011-02-24 · TA获得超过542个赞
知道小有建树答主
回答量:438
采纳率:0%
帮助的人:425万
展开全部
public class Test {
public static void main(String args[]){
int re = 0;
for(int i =1;i<=10;i++){
int r = 1;
for(int j = 1;j<=i;j++){
r = r*j ;
}
re = re + r;
}
System.out.println("1!+2!+3!+4!+5!+6!+7!+8!+9!+10!="+re);
}
运行结果:
1!+2!+3!+4!+5!+6!+7!+8!+9!+10!=4037913
追问
可以帮我全部注释上吗,我想懂多一点
追答
public class Test {
public static void main(String args[]){
int re = 0;//定义一个存储和的变量
for(int i =1;i<=10;i++){//循环做1至10的阶乘
int r = 1;//定义一个存储阶乘结果的变量
for(int j = 1;j<=i;j++){//阶乘循环
r = r*j ;//获得每个阶乘结果
}
re = re + r;//依次从1!加到10!
}
System.out.println("1!+2!+3!+4!+5!+6!+7!+8!+9!+10!="+re);
}
你可以慢慢看,用三的阶乘放到程序里试一下,你可以更快一点明白...
Jseven_jy
2011-02-24 · TA获得超过8123个赞
知道大有可为答主
回答量:2499
采纳率:100%
帮助的人:1347万
展开全部
public class Ten {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(sumFact(10));
}

/**
* 求阶乘和的方法
* 如sumFact(10)就返回1!+2!+3!+4!+5!+6!+7!+8!+9!+10!的值
* @param num
* @return
*/
public static long sumFact(int num) {
long sum = 0;
for(int i = 1; i <= num; i++) {
long sumIn = 1;
for(int j = 2; j <= i; j++)
sumIn *= j;
sum += sumIn;
}
return sum;
}

}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
贯真
2011-02-24 · TA获得超过2698个赞
知道大有可为答主
回答量:1022
采纳率:0%
帮助的人:1154万
展开全部
public class test {
public static void main(String[] args) {
System.out.print("1!+2!+3!+4!+.....+10!为:" + totalFactorial(10));
}

private static int totalFactorial(int n) {
int total = 0;//总和
int fac = 1;//阶乘
for (int i = 1; i <= n; i++) {
fac *= i;
total += fac;
}
return total;
}
}
运行结果:
1!+2!+3!+4!+.....+10!为:4037913
此例在JDK1.5中测试通过;
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友4564d7b
2011-02-24 · TA获得超过4801个赞
知道小有建树答主
回答量:232
采纳率:0%
帮助的人:0
展开全部
sum=0;
p=1;
for(int i=1;i<=10;i++){
for(int j=1;j<=i;j++){
p=p*j;
}
sum=sum+p;
}
sum就是答案喽
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
nokla99
2011-02-24
知道答主
回答量:33
采纳率:0%
帮助的人:0
展开全部
int total = 0;
int cnt = 10;
for(int i = 1 ; i < cnt + 1 ; i++)
{
int temp = 1;
for(int j = 1 ; j <= i ; j++)
{
temp *= j;
}
total += temp;
}
System.out.println(total);
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(3)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式