java中非整数值的阶乘

Wol*_*lvy 0 java factorial

5!= 5*4*3*2*1.

我对此没有任何问题.但我注意到我的程序,如果我输入说3.5!它会返回一个定义的数字.

你怎么计算它们?

我的程序中有这样的东西

 public class fact {
   public static void main(String args[]) {
     double factorial=1;
     System.out.println("Type a number");
     double number= sc.nextDouble(); /*I am using scanner*/
     while (number !=0 ){
       factorial = factorial * number;
       number--;
     }
     System.out.println(factorial);
   }
 }
Run Code Online (Sandbox Code Playgroud)

ank*_*t_m 5

其正常定义中的因子仅针对正整数定义.如果要计算任何实数的阶乘,请查看Gamma函数.

https://en.wikipedia.org/wiki/Gamma_function