Friday, March 13, 2020

Java Program on Prime Palindrome Number Checking


For Details of The Program:  CLICK HERE


import java.io.*;
class PalPrime
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int m,n;
int c;
public void showPalPrime() throws Exception
{
     c=0;
System.out.println("Enter the Lower Limit:");
m=Integer.parseInt(br.readLine());
System.out.println("Enter the Upper Limit:");
n=Integer.parseInt(br.readLine());
if(m >=n || n >=3000)
System.out.println("Out of Range.");
else
System.out.println("The Prime Palindrome integers are:");
while(m <=n)
{
if(palPrime(m))
{
if(c==0)
System.out.print(m);
else
System.out.print(", "+m);
c++;
}
m++;
}
System.out.println("\nFrequency of Prime Palindrome integers: "+c);
}
}
private boolean palPrime(int x)
{
boolean bool=false;
int i;
int rev=0;
for(i=2;i< x;i++)
{
if(x%i==0)
break;
}
if(i==x)
bool=true;
if(bool)
{
for(i=x;i >0;i=i/10)
{
rev=rev*10+i%10;
}
if(rev!=x)
bool=false;
}
return bool;
}
public static void main(String args[]) throws Exception
{
PalPrime ob=new PalPrime ();
ob.showPalPrime();
}
}


2012 Computer Practical Paper: CLICK HERE

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner