5! = 5 * 4 * 3 * 2 * 1。java中非整数值的阶乘
我对此没有任何问题。但我注意到我的程序,如果我输入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);
}
}
我不太了解您的问题?你能再详细一点吗? – Koekje
引用此链接https://math.stackexchange.com/questions/454053/how-do-we-calculate-factorials-for-numbers-with-decimal-places – tabby
阶乘函数仅为整数定义。为什么你想接受3.5作为输入? – jsheeran