码迷,mamicode.com
首页 > 其他好文 > 详细

计算阶乘

时间:2015-12-05 14:20:55      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:

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

技术分享

计算阶乘

标签:

原文地址:http://www.cnblogs.com/0927wyj/p/5021439.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!