用java编程1!+2!+3!+4!+5!+6!+7!+8!+9!+10!
3个回答
展开全部
public class Test {
public static void main(String[] args) {
System.out.println(jiecheng(10));
}
public static int jiecheng(int m) {
if (m == 1) {return 1;}
int result = 1;
for(int i = 1; i <= m; i++) {
result *= i;
}
return result + jiecheng(m - 1);
}
}
public static void main(String[] args) {
System.out.println(jiecheng(10));
}
public static int jiecheng(int m) {
if (m == 1) {return 1;}
int result = 1;
for(int i = 1; i <= m; i++) {
result *= i;
}
return result + jiecheng(m - 1);
}
}
展开全部
int temp = 1;
int jiecheng = 0;
for (int i = 1; i <= 1; i++) {
temp *= i;
jiecheng += temp;
}
System.out.println(jiecheng);
int jiecheng = 0;
for (int i = 1; i <= 1; i++) {
temp *= i;
jiecheng += temp;
}
System.out.println(jiecheng);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
package com.baidu;
public class Testjc {
/**
* @author zpf<br>
* <b>create Date:</b>Apr 15, 2010 6:55:09 PM<br>
* <b>last modify Date:</b>Apr 15, 2010 6:55:09 PM<br>
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] jcarray=new int[10];
int result=0;
for(int i=1;i<11;i++){
int jc=1;
for(int j=1;j<=i;j++){
jc*=j;
jcarray[i-1]=jc;
}
}
for(int i=0;i<jcarray.length;i++){
result+=jcarray[i];
System.out.print(jcarray[i]+"\t");
}
System.out.println();
System.out.print(result);
}
}
大概就这样吧
public class Testjc {
/**
* @author zpf<br>
* <b>create Date:</b>Apr 15, 2010 6:55:09 PM<br>
* <b>last modify Date:</b>Apr 15, 2010 6:55:09 PM<br>
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] jcarray=new int[10];
int result=0;
for(int i=1;i<11;i++){
int jc=1;
for(int j=1;j<=i;j++){
jc*=j;
jcarray[i-1]=jc;
}
}
for(int i=0;i<jcarray.length;i++){
result+=jcarray[i];
System.out.print(jcarray[i]+"\t");
}
System.out.println();
System.out.print(result);
}
}
大概就这样吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |