This site javatpoint is very useful for programming languages like JAVA,PYTHON,C,C++, Data Structures etc.Java learning Concept also provides technical materials , which are related to latest technologies. We provides very easy lectures to our viewers from beginning to advance level.We focus logical content instead of theoretical content.

Wednesday, 29 August 2018

How to write Prime number program in java(2023)

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
Adbox