请教一个简单的JAVA编程问题

来源:百度知道 编辑:UC知道 时间:2024/05/13 23:20:05
用循环语句
while
do while
for
这三中循环语句任意一个编程出 1!+2!+...9!+10!
哪位高手帮忙一下,留下QQ也可以!

class test
{
public static void main()
{
double sum=0;
int i;
int j;
double all=1;
for(i=1;i<=10;i+=1)
{
for(j=1;j<=i;j+=1)
{
all=(double)(all*j);
}
sum+=all;
}
System.out.println(sum);
}
}

int sum=0,tmp;
for(int i=1;i<=10;i++)
{
tmp=1;
for(int j=1;j<=i;j++)
tmp=tmp*j;
sum=sum+tmp;
}

这是最核心的东西!
其他的(像什么main之类的)不用我写了吧?