Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

prime numbers most efficient algorithm java

Prime number algorithm implementation in Java 8
boolean isPrime(int number) 
{
  if(number <= 2)
    return number == 2;
  else
    return  (number % 2) != 0
        &&
        IntStream.rangeClosed(3, (int) Math.sqrt(number))
        .filter(n -> n % 2 != 0)
            .noneMatch(n -> (number % n == 0));
}
Source by howtodoinjava.com #
 
PREVIOUS NEXT
Tagged: #prime #numbers #efficient #algorithm #java
ADD COMMENT
Topic
Name
2+2 =