您的位置:首页 > 其它

【第三周】第三章习题3.7

2016-09-15 21:40 330 查看
/*2016.9.15
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

/**
*编写一个应用程序求满足1+2!+3!……+N!《=9999的最大整数N
*
* @author 马康泰
*/
public class Main {
public static void main(String args[]){
int sum=0,fac=0;
int n=1;
Factorial a=new Factorial();
while(sum<=9999){
fac=a.factorial(n);
sum=sum+fac;
n++;
}
System.out.println(n);
}
}
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

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

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