Last active
August 6, 2020 17:35
-
-
Save mnadeem/fab9c666b5a415298dc16848c980eb35 to your computer and use it in GitHub Desktop.
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
int start = 1, end = 10; | |
List<Integer> primeNumbers = IntStream.range(start, end) | |
.filter(number -> number > 1 && IntStream.range(2, number).noneMatch(divider -> number % divider == 0)) | |
.boxed().collect(Collectors.toList()); | |
System.out.println(primeNumbers); | |
Integer sumOfPrimes = IntStream.range(start, end).filter( | |
number -> number > 1 && IntStream.range(2, number - 1).noneMatch(divider -> number % divider == 0)) | |
.reduce(0, (a, b) -> a + b); | |
System.out.println(sumOfPrimes); | |
Integer sumOfSquaresOfPrimes = IntStream.range(start, end).filter( | |
number -> number > 1 && IntStream.range(2, number - 1).noneMatch(divider -> number % divider == 0)) | |
.map(x -> x * x).reduce(0, (a, b) -> a + b); | |
System.out.println(sumOfSquaresOfPrimes); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment