求一个数的阶乘 您所在的位置:网站首页 计算一个数的阶乘 求一个数的阶乘

求一个数的阶乘

2022-03-26 03:16| 来源: 网络整理| 查看: 265

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

package factorial;

/** * @function:计算数的阶乘 *  * @author: Administrator */public class FactorialTest {

       //factorial方法,计算阶乘    public double factorial(int n){

        double sum = 1;

        for(int i = 1; i

        double result;

        FactorialTest f = new FactorialTest(); //声明 FactorialTest对象

        result = f.factorial(5);  //调用factorial函数,计算n的阶乘,赋值给result

        System.out.println("n! =" + result );   //打印    }}     //End



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有