Computer Science, asked by kshitijcloudline, 25 days ago

Write a program to accept a number and check and display whether it is an Emirp number or not. An Emirp number is a number which is prime backwards and forwards.

For example: 13 is an Emirp number since 13 and 31 are both prime numbers.
(Java)​

Answers

Answered by kamalrajatjoshi94
1

Answer:

Program:-

import java.util.*;

public class Emirp

{

public static void main(String args[ ])

{

Scanner in=new Scanner(System.in);

int a,b,n=0,r=0,c=0,d=0,e=0,num=0;

System.out.println("Enter the number");

n=in.nextInt();

num=n;

for(a=1;a<=n;a++)

{

if(n%a==0)

c++;

}

if(c==2)

{

System.out.println(n + " is a prime number");

while(n!=0)

{

e=n%10;

r=r*10+e;

n=n/10;

}

System.out.println("The twisted number="+r);

for(b=1;b<=r;b++)

{

if(num%r==0)

d++;

}

if(d==2)

System.out.println(r + " is a twisted prime");

System.out.println(" Hence" + num + " is Emirp number");

else

System.out.println("The number is prime but not emirp number");

}

else

System.out.println("It is neither a prime nor a emirp number");

}

}

Similar questions