[此代码有误公共课程Program7 {
public static void main(String[] args) {
long time = System.nanoTime();
long count = Stream.iterate(0, n -> n + 1)
.limit(1_000_000)
.parallel() //if you disable this row, program will execute sequentially
.filter(Program7::isPrime)
.peek(x -> System.out.format("%s\t", x));
.count();
time = System.nanoTime () - time;
System.out.printf("Elapsed %, 9.3f ms\n", time/1_000_000.0);
System.out.println("\nTotal: " + count);
}] 1
public class Program7
{
public static void main(String[] args) {
long time = System.nanoTime();
long count = Stream.iterate(0, n -> n + 1)
.limit(1000000)
.parallel() //if you disable this row, program will execute sequentially
.filter(Program7::isPrime)
.peek(x -> System.out.format("%s\t", x))
.count();
time = System.nanoTime () - time;
System.out.printf("Elapsed %, 9.3f ms\n", time/1_000_000.0);
System.out.println("\nTotal: " + count);
}
public static boolean isPrime(int n){
if(n%2==0)
return true;
else
return false;
}
}