PROGRAM : EMIRP NUMBER.
class emirp
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n,rev=0,d=0,x=0,y=0;Boolean flag=false,flag1=false;
System.out.println("Enter a Number");
n=Integer.parseInt(br.readLine());
for(int i=2;i<n;i++)
{
if(n%i==0)
x++;
}if(x==0)
flag=true;
while(n!=0)
{
d=n%10;
rev=rev*10+d;
n=n/10;
}
for(int j=2;j<=n;j++)
{
if(rev%j==0)
y++;
}
if(y==0)
flag1=true;
if((flag==true)&&(flag1==true))
{
System.out.println("It is Emirp Number");
}
else
System.out.println("It is Not Emirp Number");
}
}
An Emirp number is a number which is prime backwards and forwards. Example: 13 and 31 are both prime numbers. Thus, 13 is an Emirp number.
Design a class Emirp to check if a given number is Emirp number or not
SYNTAX:
import java.io.*;class emirp
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n,rev=0,d=0,x=0,y=0;Boolean flag=false,flag1=false;
System.out.println("Enter a Number");
n=Integer.parseInt(br.readLine());
for(int i=2;i<n;i++)
{
if(n%i==0)
x++;
}if(x==0)
flag=true;
while(n!=0)
{
d=n%10;
rev=rev*10+d;
n=n/10;
}
for(int j=2;j<=n;j++)
{
if(rev%j==0)
y++;
}
if(y==0)
flag1=true;
if((flag==true)&&(flag1==true))
{
System.out.println("It is Emirp Number");
}
else
System.out.println("It is Not Emirp Number");
}
}
Comments
Post a Comment