×
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
3307    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.
Sri Sri Ramakrishna Paramahamsa
All troubles come to an end when the ego dies
Sri Sri Ramakrishna Paramahamsa
2416
64.28
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     47382
25/06/2018     39477
01/01/2018     39090
28/06/2017     36982
02/08/2017     35708
01/08/2017     29943
06/07/2017     29728
15/05/2017     29214
14/07/2017     25097
11/09/2018     24243
softetechnologies