# (Emirp) An emirp (prime spelled backward) is a nonpalindromic prime number whose reversal is also a prime. For example, 17 is a prime and 71 is a prime, so 17 and 71 are both emirps. Write a Java program that displays the first 100 emirps. Display 10 numbers per line with a spacing of 5; all numbers should be left-aligned.

Question
232 views

(Emirp) An emirp (prime spelled backward) is a nonpalindromic prime number whose reversal is also a prime. For example, 17 is a prime and 71 is a prime, so 17 and 71 are both emirps. Write a Java program that displays the first 100 emirps. Display 10 numbers per line with a spacing of 5; all numbers should be left-aligned.

check_circle

Step 1

The Java program is written to display first 100 emrip numbers which are nonpalindromic numbers whose reverse is also prime number. The numbers are displayed with spacing of 5 and left alignment. 10 numbers are displayed per line.

Step 2

public class Emirp

{

public static void main(String[] args) {

int cnt = 0;

for (int i = 10; cnt < 100; i++) {

{

System.out.printf("%-10d", i); // left alignment with spacing of 5

cnt++;

if (cnt % 10 == 0 && i != 0) System.out.println();

}

}

}

public static boolean primeNum(long n) {

if (n < 2) return false;

for (int i = 2; i <= n / 2; i++) {

if (n % i == 0) return false;

}

return true;

}

public static long rev(long number) {

long rev = 0;

while (number != 0) {

rev *= 10;

rev += number % 10;

number /= 10;

}

return rev;

}

public static boolean palindromeNum(long number) {

return (number == rev(number));

}

}

Step 3

In the above program, three static methods are created primeNum () and palindromeNum () both in Boolean type and rev of type long. In primeNum me...

### Want to see the full answer?

See Solution

#### Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

### Object Oriented Programming 