import javax.swing.*;
public class prime
{
public static void main(String w[])
{
int x;
x=Integer.parseInt(JOptionPane.showInputDialog("Enter number"));
if (x<2)
{System.out.print(x + " is not prime\n");
}
else
{
if(x==2)
{System.out.print(x + "is prime\n");}
else
{
int t,prim;
t=(Math.round(x/2));
prim=1;
while(prim==1 && t>1)
{
if(x%t==0)
{
prim=0;}
t--;
}
if(prim==1)
{
System.out.print(x + " is prime\n");}
else
{
System.out.print(x + " is not prime\n");}
}
}
System.exit(0);
}
}
No comments:
Post a Comment