Programming Examples
Java program to check entered number is prime palindrome or not
Write a java program to enter any integer number and check number is Prime Palindrome or Not.
Solution
import java.util.*;
class PrimePalindrome
{
public static void main(String arr[])
{
Scanner sc=new Scanner(System.in);
int num,a,digit,rev=0;
boolean flag;
System.out.println("Enter any Number :");
num=sc.nextInt();
a=num;
while(a>0)
{
digit=a%10;
rev=rev*10+digit;
a=a/10;
}
if(num==rev)
{
flag=true;
for(a=2;a<num;a++)
{
if(num%a==0)
{
flag=false;
break;
}
}
if(flag==true&&num>1)
{
System.out.println("Number is Palindrome Prime");
}
else
{
System.out.println("Number is Palindrome but not Prime");
}
}
else
{
System.out.println("Number id not palindrome");
}
}
}
Output
Enter any Number :
979
Number is Palindrome but not Prime
Enter any Number :
797
Number is Palindrome Prime