forked from int28h/JavaTasks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path22.java
More file actions
16 lines (12 loc) · 852 Bytes
/
22.java
File metadata and controls
16 lines (12 loc) · 852 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/*
Create a parallel LongStream for filtering prime numbers in the given range (inclusively).
The static method NumberUtils.isPrime(...some long number...) will be available for you during testing.
It returns true if the passed value is prime and false otherwise.
Be carefully with rangeClose(d), iterate and limit methods!
Important. You need return a prepared parallel stream from the template. After calling count() it should return
the count of prime numbers in the given range. Pay attention to the method template. Do not change it.
PS: it's not a very efficient approach for generating prime numbers, it's just an example of parallel streams.
*/
public static LongStream createPrimesFilteringStream(long rangeBegin, long rangeEnd) {
return LongStream.rangeClosed(rangeBegin, rangeEnd).parallel().filter(s -> NumberUtils.isPrime(s));
}