Java第三章习题3-7(1到n的阶乘和<=9999)

来源:互联网 发布:淘宝客pid 编辑:程序博客网 时间:2024/04/30 13:00

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();    }    }


0 0
原创粉丝点击