File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ import java .util .Scanner ;
2+ public class PalindromePrime {
3+
4+ public static void main (String [] args ) { // Main funtion
5+ Scanner in = new Scanner (System .in );
6+ System .out .println ("Enter the quantity of First Palindromic Primes you want" );
7+ int n = in .nextInt (); // Input of how mant first pallindromic prime we want
8+ funtioning (n ); // calling funtion - functioning
9+ }
10+
11+ public static boolean prime (int num ) { // checking if number is prime or not
12+ for (int divisor = 2 ; divisor <= num / 2 ; divisor ++) {
13+ if (num % divisor == 0 ) {
14+ return false ; // false if not prime
15+ }
16+ }
17+ return true ; // True if prime
18+ }
19+
20+ public static int reverse (int n ){ // Returns the reverse of the number
21+ int reverse = 0 ;
22+ while (n !=0 ){
23+ reverse = reverse * 10 ;
24+ reverse = reverse + n %10 ;
25+ n = n /10 ;
26+ }
27+ return reverse ;
28+ }
29+
30+ public static void funtioning (int y ){
31+ int count =0 ;
32+ int num = 2 ;
33+ while (count < y ){
34+ if (prime (num ) && num == reverse (num )){ // number is prime and it's reverse is same
35+ count ++; // counts check when to terminate while loop
36+ System .out .print (num + "\n " ); // Print the Palindromic Prime
37+ }
38+ num ++; // inrease iterator value by one
39+ }
40+ }
41+ };
You can’t perform that action at this time.
0 commit comments