this is the method to identify the prime numbers
import java.util.*;
public class prime
{
int n;
public static void main(String args[])
{
Scanner m=new Scanner(System.in);
System.out.println("Enter your number");
int P=m.nextInt();
prime input=new prime();
input.check(P);
}
void check(int P)
{
for(int i=2;i<P;i++)
{
if(P%i!=0)
{
n=0;
}
else if(P%i==0)
{
n=1;break;
}
}
if(n==0)
{
System.out.println("prime");
}
else if(n==1)
{
System.out.println("not prime");
}
}
}
import java.util.*;
public class prime
{
int n;
public static void main(String args[])
{
Scanner m=new Scanner(System.in);
System.out.println("Enter your number");
int P=m.nextInt();
prime input=new prime();
input.check(P);
}
void check(int P)
{
for(int i=2;i<P;i++)
{
if(P%i!=0)
{
n=0;
}
else if(P%i==0)
{
n=1;break;
}
}
if(n==0)
{
System.out.println("prime");
}
else if(n==1)
{
System.out.println("not prime");
}
}
}
No comments:
Post a Comment