Ad

Reduced the range: an integer cannot be divided by a number that is more than its half.

Code
Diff
  • import java.util.stream.IntStream;
    
    public class Primes {
      public static boolean isAPrime(int number) {
        return IntStream.range(2, (number/2 +1))
          .noneMatch(divider -> (number % divider) == 0); 
      }
    }
    • import java.util.stream.IntStream;
    • public class Primes {
    • public static boolean isAPrime(int number) {
    • return IntStream.range(2, number)
    • return IntStream.range(2, (number/2 +1))
    • .noneMatch(divider -> (number % divider) == 0);
    • }
    • }