求一个数的阶乘 | 您所在的位置:网站首页 › 计算一个数的阶乘 › 求一个数的阶乘 |
/* * 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 实验室设备网 版权所有 |