Skip to content

Instantly share code, notes, and snippets.

@jyukutyo
Created January 22, 2019 08:15
Show Gist options
  • Save jyukutyo/84efbb9c06cb0ba6e88fc25a89eb0bfb to your computer and use it in GitHub Desktop.
Save jyukutyo/84efbb9c06cb0ba6e88fc25a89eb0bfb to your computer and use it in GitHub Desktop.
Prime Numbers
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