1. 程式人生 > >Java第三章習題3-7(1到n的階乘和

Java第三章習題3-7(1到n的階乘和

Find.java

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Administrator
 */
public class Find {
    public void main(){
        int n=9999;
        int sum=0;
        int k=1,i=1;
        for( i=1;i<=10;i++){
            k=k*i;
            sum=sum+k;
            if(sum>9999){
                break;
            }
        }
        System.out.println(i-1);

            
    }
    
}

Test.java

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Administrator
 */
public class Test {
    public static void main(String[] args){
        Find f=new Find();
        f.main();
    }
    
}