/*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;
}
}
【第三周】第三章习题3.7
最新推荐文章于 2022-11-13 23:54:43 发布