File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ / *
2+ Find if a number is circular prime or not .
3+ */
4+
5+ class CircularPrime
6+ {
7+ boolean isPrime (int m )
8+ {
9+ int c =0 ;
10+ for (int i =1 ; i <m ; i ++)
11+ {
12+ if (m %i ==0 )
13+ c ++;
14+ }
15+ if (c ==1 )
16+ return true ;
17+ else
18+ return false ;
19+ }
20+
21+ int countDigits (int n )
22+ {
23+ int c =0 ;
24+ while (n >0 )
25+ {
26+ n =n /10 ;
27+ c ++;
28+ }
29+ return c ;
30+ }
31+
32+ void main (int num )
33+ {
34+ int n =num ;
35+ int c =countDigits (num );
36+ int f =0 ; int t =0 ;
37+ int p =1 ;
38+ for (int i =1 ; i <c ; i ++)
39+ {
40+ p =p *10 ;
41+ }
42+ while (t !=num )
43+ {
44+ t =n %p ;
45+ int j =n /p ;
46+ t =t *10 +j ;
47+ boolean r =isPrime (t );
48+ if (r ==false )
49+ f ++;
50+ n = t ;
51+ }
52+ if (f ==0 )
53+ System .out .println (num + " is a circular prime number" );
54+ else
55+ System .out .println (num + " is not a circular prime number " );
56+ }
57+ }
You can’t perform that action at this time.
0 commit comments