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 !!");
}
}
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
Post a Comment