Circular Prime number : An easy ISC practical 2016
A number is said to be prime if it has only two factors I and itself.Example:131311113Hence, 131 is a circular prime.Test your program with the sample data and some random data:
Watch java videos
A Circular Prime is a prime number that remains prime under cyclic shifts of its digits. When the leftmost digit is removed and replaced at the end of the remaining string of digits, the generated number is still prime. The process is repeated until the original number is reached again.
A number is said to be prime if it has only two factors I and itself.
Example:
131
311
113
Hence, 131 is a circular prime.
Test your program with the sample data and some random data:
Example 1
INPUT :N = 197
OUTPUT:
197
971
719
197 IS A CIRCULAR PRIME
Example 2
INPUT :N = 1193
OUTPUT:
1193
1931
9311
3119
1193 IS A CIRCULAR PRIME
Example 3
INPUT :N = 29
OUTPUT:
29
92
29 IS NOT A CIRCULAR PRIME
import java.io.*;
class circular_prime
{
static int isPrime(int x,int j)
{
int count=0;
while(j<=x)
{
if(x%j==0)
{
count++;
}
j++;
}
return count;
}
static int checkCircular(int num)
{
int c=0;
int n=num;
String a=Integer.toString(num);
int len=a.length();
int b=(int)Math.pow(10,(len-1));
for(int i=0;i<len;i++)
{
int rem=n%10;
int rev=rem*b;
int temp=rev+(n/10);
n=temp;
if(isPrime(temp,1)==2)
{
c++;
}
}
if(c==len)
{
return 1;
}
else
{
return 0;
}
}
public static void main()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a number");
int number=Integer.parseInt(br.readLine()); if(checkCircular(number)==1)
{
System.out.println("CIRCULAR PRIME NUMBER");
}
else
{
System.out.println("NOT A CIRCULAR PRIME NUMBER");
}
}
}
Download free Sample papers
Related Posts
Continue learning with these related articles

ISC Practical 2027: Image Editor – Brighten an Image and Find Bright Spots (2-D Array) – Java Program
Fully solved ISC Computer Science Practical 2027 2-D array question: brighten a grayscale image (capping values at 255) and find the bright spots, pixels larger than all four neighbours. Includes a missing bright spot in CISCE’s sample output.

ISC Practical 2027: College Enrolment Code Validator and Stream Report – Algorithm and Java Program
Fully solved ISC Computer Science Practical 2027 question: validate college enrolment codes made of a stream, year and serial number, give the exact reason for each rejection, auto-correct lowercase streams and prepare a stream-wise report.

ISC Practical 2027: Digital Lock Security Code Analyzer – Algorithm and Java Program
Fully solved ISC Computer Science Practical 2027 number-logic question: for a 5 to 10 digit security code, find the first and last digits, odd and even position sums, product of non-zero digits, digit frequency and classify the code as STRONG, MODERATE or WEAK.