import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
class CheckEmirpNumber
{
// create object and intialize here.
static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n, rev, f;
// create parameterised constructor
CheckEmirpNumber(int nn)
{
n=nn;
rev=0;
f=2;
}
// function for checking the prime number.
int isprime(int x)
{
if(f<=x)
{
if(x%f!=0)
{
f++;
isprime(x);
}
}
if(f==x)
return 1;
else
return 0;
}
// function to check Emrip number.
void isEmirp()
{
int copy=n, d;
// reversing the number.
while(copy>0)
{
d=copy%10;
rev=rev*10+d;
copy=copy/10;
}
int a=isprime(n);
f=2;
int b=isprime(rev);
// if both a and b are equal then it is Emrip
if(a==1 && b==1)
System.out.println(n+" is an Emirp Number");
else
System.out.println(n+" is Not an Emirp Number");
}
public static void main(String args[])throws IOException
{
// Enter the number
System.out.print("Enter the number : ");
int n=Integer.parseInt(br.readLine());
// call the function to check.
CheckEmirpNumber ob=new CheckEmirpNumber(n);
ob.isEmirp();
}
}
Output
First run:
Enter any number : 13
13 is an Emirp Number
Second run:
Enter the number : 250
250 is Not an Emirp Number
Program to check Emrip number in java
Output
need an explanation for this answer? contact us directly to get an explanation for this answer