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.
Java
Java Iterative Stmts
21 Likes
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


Answered By
3 Likes
Related Questions
Give the output of following code and mention how many times the loop will execute?
int i; for( i=5; i>=1; i--) { if(i%2 == 1) continue; System.out.print(i+" "); }
To execute a loop 5 times, which of the following is correct?
Give the output of the following program segment. How many times is the loop executed?
for(x=10; x>20;x++) System.out.println(x); System.out.println(x*2);
Define a class to accept a number and check whether it is an FDS Number or not. A number is called an FDS Number if the sum of the factorials of its digits equals the number itself.
Example 1:
Input: 145
Output: FDS Number [1! + 4! + 5! = 1 + 24 + 120 = 145]Example 2:
Input: 123
Output: Not an FDS Number [1! + 2! + 3! = 1 + 2 + 6 ≠ 123]import java.util.Scanner; class KboatFDSNum { static int fact(int d) { int f = 1; _______(1)_________ { _______(2)_________ } _______(3)_________ } public static void main(String args[]) { Scanner in = new Scanner(System.in); System.out.print("Enter a number: "); int num = in.nextInt(); int t = num, sum = 0; _______(4)_________ { _______(5)_________ _______(6)_________ _______(7)_________ } _______(8)_________ { _______(9)_________ } else { _______(10)_________ } } }