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.");
  }
}

3 thoughts on “Java Program to check the Prime number”

  1. [2824]Angkasa168: Login Resmi Situs Slot Gacor & Casino Terpercaya,Angkasa168 menyediakan akses login resmi untuk main slot gacor hari ini. Download APK terbaru dan nikmati kemudahan deposit via Dana. Daftar sekarang juga! visit: angkasa168

Leave a Comment

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