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+ Write a program to check a number for palindrome prime.
3+
4+ Palindrome - A palindromic number is a number (such as 16461) that remains the same when its digits are reversed.
5+ Prime - a whole number greater than 1 that cannot be exactly divided by any whole number other than itself and 1
6+ */
7+
8+ import java .io .*;
9+ import java .util .*;
10+ public class PrimePal
11+ {
12+ public static void main (String args [])
13+ {
14+ Scanner in = new Scanner (System .in );
15+ int nm ,pn ,rev ,s =0 ,i ,c =0 ;
16+ System .out .println ("Enter No." );
17+ nm = in .nextInt (); // User input
18+ pn =nm ; // store the entered number in "pn" variable
19+ for (i =1 ;i <=pn ;i ++)
20+ {
21+ if (pn %i ==0 )
22+ {
23+ c ++;
24+ }
25+ }
26+ while (nm >0 )
27+ {
28+ rev =nm %10 ; // extract last digit of the number
29+ s =s *10 +rev ; // store the digit last digit
30+ nm =nm /10 ; // extract all digit except the last
31+ }
32+ if (pn ==s &&c ==2 ) // comparing with original number
33+ {
34+ System .out .println ("Number is PalPrime : " +pn );
35+ }
36+ else
37+ {
38+ System .out .println ("Number is not PalPrime : " +pn );
39+ }
40+ } // end of main method
41+ } // end of class
You can’t perform that action at this time.
0 commit comments