forked from sourav-122/hacktoberfest2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EmirpNumber.java
52 lines (37 loc) · 802 Bytes
/
EmirpNumber.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import java.io.*;
import java.util.*;
public class EmirpNum
{
public static boolean isPrime(int n)
{
if (n <= 1)
return false;
for (int i = 2; i < n; i++)
if (n % i == 0)
return false;
return true;
}
public static boolean isEmirp(int n)
{
if (isPrime(n) == false)
return false;
int reverse = 0;
while (n != 0)
{
int digit = n % 10;
reverse = reverse * 10 + digit;
n = n/10;
}
return isPrime(reverse);
}
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter a number to check: ");
int n=sc.nextInt();
if (isEmirp(n) == true)
System.out.println("Yes, the given number is an emirp number.");
else
System.out.println("No, the given number is not an emirp number.");
}
}