Write a program to check prime number.

Write a program to check prime number.


public class PrimeNumberAlgorithm {

public static void main(String[] args) {
isPrimeNumber(11);
}

private static void isPrimeNumber(int n) {

boolean flag = true;
int m = n / 2;

for (int i = 2; i <= m; i++) {
if (n % i == 0) {
flag = false;
break;
}
}
System.out.println(flag == true ? "Prime number !!" : "Not prime number !!");
}
}

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation