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

Latest Current Affairs 2024 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2024 Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz