forked from Kritikaadhikarii/HacktoberFest2024Repo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Twisted_prime.java
46 lines (46 loc) · 1.1 KB
/
Twisted_prime.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
//Twisted prime: A prime number is said to be twisted prime if the new number obtained after reversing digits is also a prime number.
//Example:167, 761-->also prime
import java.util.*;
class TwistedPrime
{
public static void main(String[] args)
{
System.out.println("Enter a number");
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int c=0,r=0,d;
for(int i=2;i<n;i++)
{
if(n%i==0)
{
c++;
break;
}
}
if(c==0)
{
while(n>0)
{
d=n%10;
n=n/10;
r=r*10+d;
}
for(int i=2;i<n;i++)
{
if(n%i==0)
{
c++;
break;
}
}
}
if(c==0)
{
System.out.println("The entered number is a twisted prime number");
}
else
{
System.out.println(n+"The entered number is not a twisted prime number");
}
}
}