104
Twisted Prime Number Java
The Twisted Prime number is a special prime number which is also known as the Emirp number. A number is a twisted prime number if the reverse of the number is also a prime number.
Let’s take some examples of twisted prime numbers and non-twisted prime numbers.
- 79 is a twisted prime number because after reversing it, we get 97, i.e., a prime number also.
- 43 is not a twisted prime number because after reversing it, we get 34, i.e., not a prime number.
- 37 is also a twisted prime number because after reversing it, we get 73, i.e., a prime number also.
Steps to check twisted prime number
These are the following steps that we can use to implement the logic of twisted prime number:
- Take a number from the user to check.
- After that, we check whether the number is prime or not because the twisted prime number is a prime number in itself.
- If the number is a prime number, we reverse each digit of the number to get a new number.
- If the newly generated number is prime, we print “number is a twisted prime number”. Otherwise, print “number is not a twisted prime number”.
Let’s implement the code to check whether the number is a twisted prime number or not.
TwistedPrimeNumbers.java
Output:
FindAllTwistedPrimeNumbers.java
Output:
Output:
Next TopicUgly number Java