File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ //Write a program to check if a number is Emirp or not
2+ import java .util .*;
3+
4+ class Emirp {
5+ public static void main (String args []) {
6+ Scanner sc = new Scanner (System .in );
7+ System .out .println ("Enter any number" ); // Input number from the user
8+ int n = sc .nextInt ();
9+ int r = 0 ;
10+ boolean prime = true ;
11+ boolean emirp = true ;
12+ for (int x = 2 ; x < n ; x ++) { // to check whether the number is prime or not
13+ if (n % x == 0 ) {
14+ prime = false ;
15+ break ;
16+ }
17+ }
18+ if (prime ) {
19+ for (int x = n ; x != 0 ; x /= 10 ) { // to reverse the number inputted
20+ int d = x % 10 ;
21+ r = r * 10 + d ;
22+ }
23+ for (int x = 2 ; x < n ; x ++) { // to check the reversed number for being prime or not
24+ if (r % x == 0 ) {
25+ emirp = false ;
26+ break ;
27+ }
28+ }
29+ if (emirp ){
30+ System .out .println (n +" is an Emirp Number" );
31+ }
32+ else {
33+ System .out .println (n +" is not an Emirp Number" );
34+ }
35+ }
36+ else {
37+ System .out .println (n +" is not a Prime number and hence cannot be an Emirp Number" );
38+ }
39+ }
40+ }
You can’t perform that action at this time.
0 commit comments