Answer-
/**
*
* @author Ravi from CSDT
* Prime number is a number that is greater than 1 and divided by 1 or itself only.
* For example 2, 3, 5, 7, 11, 13, 17,19,23,29.... are the prime numbers.
* Note:- 0 and 1 are not prime numbers.
* 2 is the only even prime number because all the other even numbers can be divided by 2.
*/
package prime_number_java_program;
import java.util.Scanner;
public class Prime_Number_Java_Program
{
public static void main(String[] args)
{
// Prime Number Program in Java Language.
Scanner sc=new Scanner(System.in);
System.out.println("Enter an integer Number ");
int num = sc.nextInt();
boolean flag = false;
for(int i = 2; i <= num/2; ++i)
{
// condition for checking non-prime number
if(num % i == 0)
{
flag = true;
break;
}
}
if (!flag)
System.out.println(num + " is a prime number.");
else
System.out.println(num + " is not a prime number.");
}
}