# Java Program to Determine Whether an Input Positive Integer is Prime

How can we write a Java program to determine whether an input positive integer is prime?

To write a Java program that determines whether an input positive integer is prime, we can follow the steps below. Let's walk through the explanation and code snippet provided.

## Understanding Prime Numbers:

## Java Program to Determine Prime Number:

To determine whether an input positive integer is prime, we can use the following Java program:**import java.util.Scanner;**

**public class Main {**

**public static void main(String[] args) {**

**Scanner input = new Scanner(System.in);**

**System.out.print("Enter a positive integer: ");**

**int num = input.nextInt();**

**boolean isPrime = true;**

**if (num <= 1) {**

**isPrime = false;**

**} else {**

**for (int i = 2; i <= Math.sqrt(num); i++) {**

**if (num % i == 0) {**

**isPrime = false;**

**break;**

**}**

**}**

**}**

**if (isPrime) {**

**System.out.println(num + " is prime");**

**} else {**

**System.out.println(num + " is not prime");**

**}**

**}**

**}**