import java.util.Scanner;

public class VerificaPrimo {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Digite um número inteiro: ");
        int n = scanner.nextInt();

        if (n <= 1) {
            System.out.println("Não primo");
        } else {
            boolean ehPrimo = true;
            for (int i = 2; i <= Math.sqrt(n); i++) {
                if (n % i == 0) {
                    ehPrimo = false;
                    break;
                }
            }
            if (ehPrimo) {
                System.out.println("Primo");
            } else {
                System.out.println("Não primo");
            }
        }
    }
}

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: