Computer Applications
Write a program to input a number and find whether the number is an emirp number or not. A number is said to be emirp if the original number and the reversed number both are prime numbers.
For example, 17 is an emirp number as 17 and its reverse 71 are both prime numbers.
Answer
import java.util.Scanner;
public class KboatEmirp
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter Number: ");
int num = in.nextInt();
int c = 0;
for (int i = 1; i <= num; i++) {
if (num % i == 0) {
c++;
}
}
if (c == 2) {
int t = num;
int revNum = 0;
while(t != 0) {
int digit = t % 10;
t /= 10;
revNum = revNum * 10 + digit;
}
int c2 = 0;
for (int i = 1; i <= revNum; i++) {
if (revNum % i == 0) {
c2++;
}
}
if (c2 == 2)
System.out.println("Emirp Number");
else
System.out.println("Not Emirp Number");
}
else
System.out.println("Not Emirp Number");
}
}
Output




Related Questions
Define a class to accept a number and check whether it is a SUPERSPY number or not. A number is called SUPERSPY if the sum of the digits equals the number of the digits.
Example1:
Input: 1021 output: SUPERSPY number [SUM OF THE DIGITS = 1+0+2+1 = 4, NUMBER OF DIGITS = 4 ]
Example2:
Input: 125 output: Not an SUPERSPY number [1+2+5 is not equal to 3]
To execute a loop 5 times, which of the following is correct?
How many times will the following loop execute? Write the output of the code:
int x=10; while (true){ System.out.println(x++ * 2); if(x%3==0) break; }
How many times will the following loop execute?
int a = 5; while (a > 0) { System.out.println(a-- + 2); if (a % 2 == 0) break; }