[Question 1] ISC 2016 Computer Practical Paper Solved – Circular Prime
Question 1:
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.
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.
131
311
113
Hence, 131 is a circular prime.
Test your program with the sample data and some random data:
Example 1INPUT :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
SOURCE CODE
import java.io.*;
class ISC2016_CircularPrime
{
boolean isPrime(int n)
{
int c=0;
for(int i=2;i<=n;i++)
{
if(n%i==0)
c++;
}
if(c==1)
return true;
else
return false;
}
int caLc(int n)
{
String s=String.valueOf(n);
String s2=s.substring(1)+s.charAt(0);
int a=Integer.parseInt(s2);
return a;
}
void cicP(int n)
{
int nn=n,flag=0;
do
{
if(isPrime(nn)==false )
{
flag=1;
break;
}
else
{
System.out.println(nn);
nn=caLc(nn);
}
}
while(nn!=n);
System.out.println("\nOUTPUT");
if(flag==1)
{
System.out.println(nn+" IS NOT A CIRCULAR PRIME ");
}
else
{
System.out.println(nn+" IS A CIRCULAR PRIME");
}
}
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter a number :");
int n=Integer.parseInt(br.readLine());
ISC2016_CircularPrime obj=new ISC2016_CircularPrime();
obj.cicP(n);
}
}
OUTPUT
If you have any question then leave a comment below I will do my best to answer that question.
If you have any question then leave a comment below I will do my best to answer that question.
nalibmensse Heather Johnson click
ReplyDeleteomulelfis