PalPrime Number in JAVA

Palindromic Prime Number in JAVA

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 :-
  1. Get the number to check for PalPrime Number
  2. Hold the number in temporary variable
  3. Using loop find if it is prime or not.
  4. Check if the number is Palindrome or not.
  5. If the number is both prime and palindrome print "PalPrime Number"
  6. 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

All the best :)

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

Follow me on Instagram

Comments

  1. It was very much helpful.... thnk u....

    ReplyDelete
    Replies
    1. It was my pleasure to help you
      Keep Learning :)

      Delete
  2. Not helpful
    Very much confusing

    ReplyDelete
    Replies
    1. Hi! I'm sorry to hear that it is not helpful for you. Please checkout this video (link : https://youtu.be/iRL0v805om8). If you still find this not helpful than let me know.

      Delete
    2. It was really helpful but please also write the output for the programs (it applies for this one also) .

      Delete
    3. Okay! Sure I'll update the posts in few days. Thanks for your comment :)

      Delete
  3. This is the Worst website i have ever seen !! Not at all helpful....

    ReplyDelete
    Replies
    1. Hi! I'm sorry to hear that it is not helpful for you. Can you please elaborate why you feel that it is not helpful?

      Delete
  4. It was very helpful to me sir๐Ÿ‘๐Ÿ‘๐Ÿ‘

    ReplyDelete
    Replies
    1. Thanks for your comment. You can Follow me on Instagram (@bluejcode).
      Keep Learning :)

      Delete
    2. It is very helpful but only output or dry run is needed

      Delete
    3. Even I need to the output and dryrun

      Delete
    4. Please contact me on Instagram(@bluejcode) if possible. I will surely help you out.

      Delete
  5. Very helpful ๐Ÿ‘๐Ÿ‘๐Ÿ‘

    ReplyDelete
    Replies
    1. Thanks, Do checkout my Youtube Channel (https://www.youtube.com/bluejcode/)

      Delete
  6. Replies
    1. Yes I am from IIES. Please contact me on Instagram(@bluejcode).

      Delete
  7. Replies
    1. Thanks, You can also follow me on Instagram, Twitter (@bluejcode)

      Delete
  8. Really ****ing awesome. This is exactly how I wanted. My school teaches in this way only.

    ReplyDelete

Post a Comment

Popular posts from this blog

Frequency of each digit of a number in Java

Trimorphic Number in JAVA

Tri-Automorphic Number in JAVA