當n等於50時,此函數返回一個負數,是否有替代LongStream的「BigIntegerStream」,允許「n」變大?LongStream Java rangeClosed reduce - 如何避免負面回報?
public static long factorial(int n) {
if (n > 50 || n < 0)
throw new IllegalArgumentException(n + " is out of range");
return LongStream.rangeClosed(2, n).reduce(1, (a, b) -> a * b);
}
是的。 '流'。 –
Tunaki