Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CheckPrimeNumber {
- // Số Nguyên Tố là số chỉ chia hết cho 1 và chính nó
- public static void main(String[] args) {
- int n;
- Scanner sc = new Scanner(System.in);
- System.out.print("Input n: ");
- n = sc.nextInt();
- if (n > 0) {
- if (isPrimeNumber(n)) {
- System.out.println(n + " is Prime Number");
- } else {
- System.out.println(n + " is not Prime Number");
- }
- }
- }
- public static boolean isPrimeNumber(int n) {
- int flag = 0;
- for (int i = 1; i <= n; i++) {
- if (n % i == 0) {
- flag++;
- }
- }
- if (flag == 2) {
- return true;
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement