kalin729

Prime Number Checker

Oct 7th, 2021 (edited)
454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.53 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.         System.out.print("n=");
  8.         int n = scanner.nextInt();
  9.         boolean isPrime = false;
  10.         for (int i = 2; i <= n / 2; ++i) {
  11.             if (n % i == 0) {
  12.                 isPrime = true;
  13.                 break;
  14.             }
  15.         }
  16.  
  17.         if (!isPrime)
  18.             System.out.println("Yes");
  19.         else
  20.             System.out.println("No");
  21.     }
  22.  
  23.     }
  24.  
Add Comment
Please, Sign In to add comment