我如何为我更正此Java代码.count(); [关闭]

问题描述 投票:-3回答:1

[此代码有误公共课程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

javascript java javac
1个回答
0
投票
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;
    }
}

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.