Hello I currently have this piece of code for finding factorial which is work fine
public static BigInteger factorial(BigInteger n) {
BigInteger sum = BigInteger.ONE;
for (BigInteger i = BigInteger.ONE; i.compareTo(n) <= 0; i = i.add(BigInteger.ONE)) {
sum = sum.multiply(i);
}
return sum;
}
What I want to achieve is to convert this to a Stream<BigInteger>
and write it like this
public static BigInteger factorial(BigInteger n) {
return getBigIntegerStream(n).reduce(BigInteger.ONE, BigInteger::multiply);
}
So my question is how I can get a Stream<BigInteger>
similar to how I can declare an IntStream
?
IntStream.range(1, myInt);