Circular Prime in JAVA

Hello guys, if you are looking for a tutorial which would help you to determine if a number inputted by the user is Circular Prime or Not in Java, then you came to the right place. In this tutorial I will explain the solution through programming in java, but first let us take a look at what a Circular prime number is.

A number can be referred to as circular prime only if the number generated at each intermediate step when cyclically permuting its (base 10) digits will be prime. For example :

  1. 113
  2. 311
  3. 131

Since all these three numbers are prime, they can be referred as Circular Prime.

Also read:

Check if a number is a circular prime or not in Java:

import java.util.*;
class circularprime
{   String strn;int i,l,div=1,rem,copyno,n,rtn;
    Scanner sc=new Scanner(; 
    public void main()
        System.out.println("enter the number");
            div=div*10;// to store multiple of 10,to divide
    public  int ifprime(int n)
    {int count=0;
      { if(n%i==0)
      System.out.println("Circular prime");
      System.out.println("Not-Circular Prime");       
     return 0;
    public int compute(int num,int l)
    {int i=0;
      { rem=n%10;
     return 0;

Output :

enter the number
Circular prime
Explanation :

The program begins by importing util package, which would help us by enabling scanner class. We then Set the class, and declare Global variables. In addition to the Main method, we have the ‘ifprime’ method which would help us determine if the number is prime or not, and compute which would display all the permuted values for of the number inputted.
In the main method, the user is first asked to enter a  number, which is converted in a string format, to get the length of the number, which would help us determine how many digits it has. We then create the counter ‘div’ which would help us to keep the digits in their respective position. The next step is calling the other two methods, which would print out all the permuted values of the number; and check if the number is prime respectively.

One response to “Circular Prime in JAVA”

  1. Sankaran says:

    That’s cool….Thanks a lot

Leave a Reply

Your email address will not be published. Required fields are marked *