×
FREE ASSISTANCE FOR THE INQUISITIVE PEOPLE
Tutorial Topics
X
softetechnologies
Object oriented Basic theory
Emirp number - Java Program - Java
14407    Arnab De    20/07/2018

Emirp number - Java Program

An Emirp number is a number which is prime backwards and forwards. Now write a program to check a number is Emirp number or not.

If we write the word "prime" backward, then it generate a word called "Emirp". Emirp number is refers to a prime number that becomes a prime number when we reverse its digits. but the palindrom prime numbers are not included as Emirps(like 151 or 787) nor 1-digit primes like 7.

Example: 13 is an Emirp number since 13 and 31 are both prime numbers. Some others examples are 17, 107, 113, 149, and 157

import java.util.*;
public class Emirp
{
    public boolean IsPrime(int i)
    {
        boolean b=true;
        int d=2;
        while(d<i/2)
        {
            if (i%d==0)
            {
                b=false;
                break;
            }
            d++;
        }
        return b;
    }
    public static void main(String []args)
    {
        int i,r1=3,r2=100;
        Emirp ep=new Emirp();
        Scanner sc=new Scanner(System.in);
        System.out.print("Enter A Number : ");
        int no=sc.nextInt();
        int fr=no;
        int rev=0;
        while(no>0)
        {
            rev = (rev*10) + (no%10);
            no /= 10;
        }
        if(ep.IsPrime(fr) && ep.IsPrime(rev))
        {
            System.out.print(fr + " is a Emirp Number");
        }
        else
        {
            System.out.print(fr + " is not a Emirp Number");
        }
    }
}

Enter A Number : 17

17 is a Emirp Number

Enter A Number : 51

51 is not a Emirp Number

Object oriented Basic theory
softetechnologies
Author Details
Arnab De
I have over 16 years of experience working as an IT professional, ranging from teaching at my own institute to being a computer faculty at different leading institute across Kolkata. I also work as a web developer and designer, having worked for renowned companies and brand. Through tutorialathome, I wish to share my years of knowledge with the readers.
Enter New Comment
Comment History
No Comment Found Yet.
Sri Sri Ramakrishna Paramahamsa
Do yourself what you wish others to do.
Sri Sri Ramakrishna Paramahamsa
6179
84.64
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     54733
25/06/2018     45842
01/01/2018     44059
28/06/2017     41606
02/08/2017     40703
01/08/2017     34696
06/07/2017     34477
15/05/2017     33693
11/09/2018     31240
14/07/2017     30554
softetechnologies