计算阶乘

public class homework {

    public static void main(String[] args) {
        
        // 用循环实现阶乘

        int n = 4;
        //4! = 1*2*3*4=24
        long l = 1;//阶乘计算结果
        
        for(int i = 1;i<=n;i++){
         
            l = l*i;
            System.out.println("l="+l);
            
        }
        System.out.println(n+ "!="+l);
        double t =0;
        long u =1;{
        for(int i =1;i<=20;i++){
            u=u*i;
            t =t+1/(double)u;
        }
        System.out.println("测试"+"!="+t)    ;
    
        }
    
    

posted @ 2015-12-05 13:34  秦萧不再  阅读(153)  评论(0编辑  收藏  举报