×
FREE ASSISTANCE FOR THE INQUISITIVE PEOPLE
Tutorial Topics
X
softetechnologies
Write a Java program to transpose of a matrix. JAVA Practical ISC 2016 Solve - Start and End Vowel
JAVA Practical Question ISC 2016 Solve - Circular Prime - Java
3100    Arnab De    09/08/2019

This program is selected from ISC 2016 Computer Science or Class 12 practical paper.

A Circular prime is a prime number that remains a prime under cyclic shifts of its digits. When left most digits is removed and replaced at the end of the remaining string of the 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 1 and itself.

Examples 1:

  • 131
  • 311
  • 113

Hence,131 is a circular prime

Accept a positive number N and check whether it is a circular prime or not. The new number formed after the shifting of the digits should also be displayed.

softetechnologies
import java.util.*;
public class CircularPrime
{
    public static void main(String []args)
    {
        Scanner sc=new Scanner(System.in);
        CircularPrime cp=new CircularPrime();
        Boolean flag=true;
        System.out.print("Enter A Number : ");
        int noi=sc.nextInt();
        String nos=String.valueOf(noi);
        int len=nos.length();
        
        for(int i=1;i<=len;i++)
        {
            System.out.println(nos);
            if(!cp.IsPrime(nos))
            {
                flag=false;
                
            }
            nos=cp.changeNumber(nos);
        }
        if(flag)
        {
            System.out.print(noi + " is a Circular Prime No");
        }
        else
        {
            System.out.print(noi + " is not a Circular Prime No");
        }
    }
    String changeNumber(String n)
    {
        String s="";
        s=n.substring(1)+n.substring(0,1);
        return s;
    }
    boolean IsPrime(String n)
    {
        int no=Integer.parseInt(n);
        boolean b=true;
        int d=2;
        while(d<=Math.sqrt(no))
        {
            if(no%d==0)
            {
                b=false;
                break;
            }
            d++;
        }
        return b;
    }
}
softetechnologies

Test with the no 1193
Enter A Number : 197
197
971
719
197 is a Circular Prime No

Test with the no 131
Enter A Number : 131
131
311
113
131 is a Circular Prime No

Test with the no 1193
Enter A Number : 1193
1193
1931
9311
3119
1193 is a Circular Prime No

Test with the no 29
Enter A Number : 29
29
92
29 is not a Circular Prime No

Write a Java program to transpose of a matrix. JAVA Practical ISC 2016 Solve - Start and End Vowel
softetechnologies
Author Details
Arnab De
I have over 16 years of experience working as an IT professional, ranging from teaching at my own institute to being a computer faculty at different leading institute across Kolkata. I also work as a web developer and designer, having worked for renowned companies and brand. Through tutorialathome, I wish to share my years of knowledge with the readers.
Enter New Comment
Comment History
No Comment Found Yet.
Swami Vivekananda
You cannot believe in God until you believe in yourself.
Swami Vivekananda
971
58.53
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     44001
01/01/2018     36614
25/06/2018     35920
28/06/2017     34654
02/08/2017     33154
01/08/2017     27623
06/07/2017     27341
15/05/2017     26989
14/07/2017     22634
21/04/2018     21243
softetechnologies