Created
January 22, 2019 08:15
-
-
Save jyukutyo/84efbb9c06cb0ba6e88fc25a89eb0bfb to your computer and use it in GitHub Desktop.
Prime Numbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public List<Integer> primeNumbersTill(int n) { | |
return IntStream.rangeClosed(2, n) | |
.filter(x -> isPrime(x)) | |
.boxed() | |
.collect(Collectors.toList()); | |
} | |
private boolean isPrime(int number) { | |
return IntStream.rangeClosed(2, (int) (Math.sqrt(number))) | |
.allMatch(n -> number % n != 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment