Java: Check if a given number is circular prime or not
Check Circular Prime Number
Write a Java program to check if a given number is a circular prime or not.
Circular Prime : A circular prime is a prime number with the property that the number generated at each intermediate step when cyclically permuting its (base 10) digits will be prime.
For example, 1193 is a circular prime, since 1931, 9311 and 3119 all are also prime. A circular prime with at least two digits can only consist of combinations of the digits 1, 3, 7 or 9, because having 0, 2, 4, 6 or 8 as the last digit makes the number divisible by 2, and having 0 or 5 as the last digit makes it divisible by 5.
Test Data
Input a number: 35
Pictorial Presentation:
Sample Solution:
Java Code:
Sample Output:
Input a number: 35 It is not a Circular Prime number.
Flowchart:
For more Practice: Solve these Related Problems:
- Write a Java program to generate all cyclic permutations of a number and check if every rotation is prime.
- Write a Java program to determine the circular prime property using iterative digit rotation and a prime sieve.
- Write a Java program to find circular primes in a given range using Java streams for filtering.
- Write a Java program to optimize circular prime checking by rejecting numbers with non-candidate digits early.
Go to:
PREV : Check Amicable Numbers.
NEXT : Check Cube Number.
Java Code Editor:
Contribute your code and comments through Disqus.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.