Skip to content

Commit 6ad7661

Browse files
Merge pull request #94 from dineshparekh11/dinesh2
Solution to check a number for palindrome prime
2 parents ce7f23c + 94a7fd6 commit 6ad7661

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

Number Theory/PrimePal.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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

0 commit comments

Comments
 (0)