- Let's implement the APIs in the com.packt.math.MathUtil class, starting with the isPrime(Integer number) API:
public static Boolean isPrime(Integer number){ if ( number == 1 ) { return false; } return IntStream.range(2,num).noneMatch(i -> num % i == 0 ); }
- Implement the sumOfFirstNPrimes(Integer count) API:
public static Integer sumOfFirstNPrimes(Integer count){ return IntStream.iterate(1,i -> i+1) .filter(j -> isPrime(j)) .limit(count).sum(); }
- Let's write a function to check whether the number is even:
public static Boolean isEven(Integer number){ return number % 2 == 0; }
- The negation of isEven tells us whether the number is odd. We ...