Prime Number :
Generally prime number is a number which have exactly two factors.The number .either divide by one or itself only called prime number,like 2,3,5,7.11,13,17,19 etc.
Example: Let's discuss through the program
import java.util.Scanner;
class Test
{
int n,count=0,i;
public void getData()
{
System.out.println("enter the number");
Scanner sc=new Scanner(System.in);
n=sc.nextInt();
}
public void result()
{
for(i=1;i<=n;i++)
{
if(n%i==0)
{
count++;
}
}
if(count==2)
{
System.out.println("number is prime number");
}
else
{
System.out.println("number is not prime number");
}
}
}
class Demo
{
public static void main(String[] args)
{
Test t=new Test();
t.getData();
t.result();
}
}
output:
enter the number
5
number is prime number