public class EMIRP_number
{
public static boolean check(int n)
{
int count=0;
for(int i=1;i<n;i++)
{
if(n%i==0)
count++;
}
if(count==1)
return true;
return false;
}
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number");
int n = sc.nextInt();
int n1 = n;
boolean b1 = check(n);
int rev = 0;
while(n!=0)
{
int mod = n%10;
rev = rev*10+mod;
n/=10;
}
boolean b2 = check(rev);
if(b1==true && b2==true)
System.out.println(n1+" is an EMIRP number");
else
System.out.println(n1+" is not an EMIRP number");
}
}
/*
Input : n = 13
Output : 13 is Emirp!
Explanation :
13 and 31 are both prime numbers.
Thus, 13 is an Emirp number.
Input : n = 27
Output : 27 is not Emirp.
*/
No comments:
Post a Comment