pal prime number program in java

Solutions on MaxInterview for pal prime number program in java by the best coders in the world

showing results for - "pal prime number program in java"
Luca
04 Jan 2018
1import java.util.*;
2class PalPrime
3{
4    public static void main(String args[])
5    {
6        Scanner in= new Scanner(System.in);
7        int n,p,rev,s=0,i,c=0;
8        System.out.println("Enter No.");
9        n= in.nextInt(); // Input number from user
10        p=n; // store the entered number in "p" variable
11        for(i=1;i<=p;i++)
12        {
13            if(p%i==0)
14            {
15                c++;
16            }
17        }
18        while(n>0)
19        {
20            rev=n%10; // extract last digit of the number
21            s=s*10+rev; // store the digit last digit
22            n=n/10; // extract all digit except the last
23        }
24        if(p==s&&c==2) // comparing with original number
25        {
26            System.out.println("Number is PalPrime : "+p);
27        }
28        else
29        {
30            System.out.println("Number is not PalPrime : "+p);
31        }
32    } // end of main method
33} // end of class