Answers for "java prime numbers 1 to 1000000"

2

java prime numbers 1 to 1000000

public class Main {
  public static void main(String[] args) {
    for (int i = 2; i < 1_000_000; ++i) {
      boolean isPrime = true;
      int sqrt = (int)Math.ceil(Math.sqrt(i));
      for (int divisor = 2; divisor <= sqrt; ++divisor) {
        if (i % divisor == 0) {
          isPrime = false;
          break;
        }
      }
      if (isPrime) {
        System.out.println(i);
      }
    }
  }
}
Posted by: Guest on January-25-2021

Code answers related to "java prime numbers 1 to 1000000"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language