top of page
Writer's pictureSatyam Gupta

PalPrime Number in JAVA

Updated: Apr 30, 2019

PalPrime Number also known as Palindromic Prime Number


If a number is simultaneously palindromic and prime then it is said to be a PalPrime Number.

Example: Number 313, 353 etc are PalPrime number.


Algorithm and Program below :-

The video link of this program is provided at the end of this post.

 

ALGORITHM :-

  • Get the number to check for PalPrime Number

  • Hold the number in temporary variable

  • Using loop find if it is prime or not.

  • Check if the number is Palindrome or not.

  • If the number is both prime and palindrome print "PalPrime Number"

  • If not print "Not a PalPrime Number"

 

PROGRAM below :-


import java.io.*; import java.util.*; class PalPrime {     public static void main(String args[])     {         Scanner in= new Scanner(System.in);         int n,p,rev,s=0,i,c=0;         System.out.println("Enter No.");         n= in.nextInt(); // Input number from user         p=n; // store the entered number in "p" variable         for(i=1;i<=p;i++)         {             if(p%i==0)             {                 c++;             }         }         while(n>0)         {             rev=n%10; // extract last digit of the number             s=s*10+rev; // store the digit last digit             n=n/10; // extract all digit except the last         }         if(p==s&&c==2) // comparing with original number         {             System.out.println("Number is PalPrime : "+p);         }         else         {             System.out.println("Number is not PalPrime : "+p);         }     } // end of main method } // end of class

 

Note : The program is written in the easiest way possible so try understand it. If you face any problem in understanding this program than feel free to contact/comment.



All the best :)

Keep Learning :)


Watch this Program Video : https://youtu.be/iRL0v805om8


1,312 views0 comments

Recent Posts

See All

Comentários


Post: Blog2_Post
bottom of page