This number checks wether a number is prime as well as palindrom
import java.io.*;
class Primepalindrom
{
public void accept()throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a Number");
int n=Integer.parseInt(br.readLine());
Primepalindrom p = new Primepalindrom();
p.checkprime(n);
}
void checkprime(int n)
{
int i = 1;
double s=0;
int fact;
for(i=1;i<=n;i++)
{
if(n%i==0)
s=s+1;
}
if(s==2)
{
Primepalindrom p = new Primepalindrom();
p.checkpalindrom(n);
}
else
System.out.println("the number is not prime");
}
void checkpalindrom(int n)
{
int d,x,dup=0;
d=n;
do
{
x=d%10;
dup= dup*10+x;
d=d/10;
}
while(d>0);
if(dup==n)
System.out.println("The number is primepalindrom");
else
System.out.println("the number is not primepalindrom");
}
public static void main(String args[])throws IOException
{
Primepalindrom p = new Primepalindrom();
p.accept();
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment