To check whether the given number is prime
import javax.swing.JOptionPane;
public class Prime {
public static void main(String[] args)
{
boolean bFlag=true;
int iVar=Integer.parseInt(JOptionPane.showInputDialog("Enter an integer value"));
for (int i=2 ; i<=iVar/2 ; i++)
{
if (iVar%i == 0)
{
System.out.print("The number is not prime");
bFlag=false;
break ;
}
}
if( bFlag == true )
{
System.out.print("The number is prime");
}
{
boolean bFlag=true;
int iVar=Integer.parseInt(JOptionPane.showInputDialog("Enter an integer value"));
for (int i=2 ; i<=iVar/2 ; i++)
{
if (iVar%i == 0)
{
System.out.print("The number is not prime");
bFlag=false;
break ;
}
}
if( bFlag == true )
{
System.out.print("The number is prime");
}
}
}
No comments:
Post a Comment