import java.util.Scanner;
public class PrimeNumberCheck {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
boolean isPrime = true;
for (int i = 2; i <= n - 1; i++) {
if (n % i == 0) { // n is multiple of i (i not equal to 1 or n)
isPrime = false;
}
}
if (isPrime == true) {
System.out.print(n + " is prime number");
} else {
System.out.print(n + " is not prime number");
}
}
}
import java.util.Scanner;
public class PrimeNumberCheck {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
boolean isPrime = true;
for (int i = 2; i <= n - 1; i++) {
if (n % i == 0) { // n is multiple of i (i not equal to 1 or n)
isPrime = false;
}
}
if (isPrime == true) {
System.out.print(n + " is prime number");
} else {
System.out.print(n + " is not prime number");
}
}
}
No comments:
Post a Comment