Emirp number is a number when both the number and its reverse value are prime numbers.
13 is an examples of Emirp Number as both 13 and 31 are prime numbers
This is a BlueJ Program to check whether the entered number is Emrip or not.
import java.util.*;
public class Duck
{
Scanner sc=new Scanner(System.in);
public void takeNumber()
{
System.out.print("\nEnter the number:");
int n=sc.nextInt();
int rev=0;
for(int i=n;i >0;i=i/10)
{
rev=rev*10+i%10;
}
if(prime(n) && prime(rev))
System.out.print("\nEntered number is an Emirp number.");
else
System.out.print("\nEntered number is not an Emirp number.");
}
private boolean prime(int n)
{
int i;
for(i=2;i<=n-1;i++)
{
if(n%i==0)
break;
}
if(i<=n-1)
return false;
else
return true;
}
public static void main(String args[])
{
Duck obj=new Duck();
obj.takeNumber();
}
}
Related Post: BlueJ Programs on Number
No comments:
Post a Comment