您的位置:首页 > 其它

【第三周】第三章习题3.5

2016-09-17 14:31 239 查看
//2016.9.17
//马康泰
//编写一个应用程序求1!+2!+...+20!。
public class Test {
public static void main(String args[]){
int sum=0,fac=0;
int n=1;
Factorial a=new Factorial();
while(n<21){
fac=a.factorial(n);
sum=sum+fac;
n++;
}
System.out.println(sum);
}

}

public class Factorial {
public int factorial(int i){//阶乘
int j,result=1;
for(j=1;j<=i;j++){
result=result*j;
}
return result;
}

}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: