Java Program to check the Prime number

Prime number is a number that is greater than 1 and divided by 1 or itself only. 2, 3, 5, 7, 11, 13, 17…. are examples of prime numbers.

Please Note that 0 and 1 are not prime number

public class PrimeExample {
  public static void main(String[] args) {
    int number = 17;
    boolean isPrime flag = false;
    for (int i = 2; i <= num / 2; ++i) {
          if (number % i == 0) {
			isPrime = true;
			break;
      }
    }
    if (!isPrime)
      System.out.println(number + " is a prime number.");
    else
      System.out.println(number + " is not a prime number.");
  }
}

Leave a Comment

Your email address will not be published. Required fields are marked *