java prime numbers from 1 to 100

Solutions on MaxInterview for java prime numbers from 1 to 100 by the best coders in the world

showing results for - "java prime numbers from 1 to 100"
Ignacio
19 Jan 2018
1public class Main {
2  public static void main(String[] args) {
3    for (int i = 2; i < 100; ++i) {
4      boolean isPrime = true;
5      int sqrt = (int)Math.ceil(Math.sqrt(i));
6      for (int divisor = 2; divisor <= sqrt; ++divisor) {
7        if (i % divisor == 0) {
8          isPrime = false;
9          break;
10        }
11      }
12      if (isPrime) {
13        System.out.println(i);
14      }
15    }
16  }
17}