Ad
  • Custom User Avatar

    Sorry - it must be:

    int maxtest = (int) Math.sqrt(num)+1;  
    return IntStream.range(2, maxtest).noneMatch(divider -> (num % divider) == 0); 
    
  • Custom User Avatar

    The endvalue of then IntStrem can be the squareroot of num. If no lower divider is found, there is no at all!

    int maxtest = (int) Math.sqrt(num);  
    return IntStream.range(2, maxtest).noneMatch(divider -> (num % divider) == 0); 
    

    Thats much faster!