Question

Check whether a number is a Prime Palindrome number.

A prime palindrome integer is a positive integer (without leading zeroes) which is prime as well as a palindrome. 

				
					ENTER THE NUMBER
101
101 IS A PRIME PALINDROME NUMBER
				
			

Share code with your friends

Share on whatsapp
Share on facebook
Share on twitter
Share on telegram

Code

				
					import java.util.Scanner;
public class PrimePalindromeNumber
{
    public static void main(String args[])
    {
        long num=0,temp=0,i=0,reverse=0;
        int flag=0;
        boolean isPrime=false,isPalindrome=false;
        Scanner sc=new Scanner(System.in);
        System.out.println("ENTER THE NUMBER");
        num=sc.nextLong();
        temp=num;

        if(temp<2)
        {  
            isPrime=false;    
        }
        else
        {  
            /*for loop runs till "n/2" because number is divisible perfected till half the number*/
            for(i=2;i<=temp/2;i++)  
            {
                /*Checking if number is divisible by i.*/
                if(temp%i==0)
                {      
                    isPrime=false; 
                    flag=1;
                    break;      
                }      
            }      
            if(flag==0)
            {
                isPrime=true;
            }  
        }
        
        temp=num;
        reverse=0;
        while(temp>0)
        {
            reverse=reverse*10+temp%10;
            temp=temp/10;
        }
        if(reverse==num)
        {
            isPalindrome=true;  
        }
        else
        {
            isPalindrome=false; 
        }

        if(isPrime==true && isPalindrome==true)
        {
            System.out.println(num+" IS PRIME PALINDROME NUMBER");   
        }
        else
        {
            System.out.println(num+" IS NOT PRIME PALINDROME NUMBER");   
        }
    }

}    



				
			

Coding Store

Leave a Reply

Your email address will not be published. Required fields are marked *