answersLogoWhite

0

import java.io.*;

class PalPrime

{

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

int x;

void inputData(int X)throws IOException

{

x=X;

}

int Pal(int y)

{

int a=y,b=0,rev=0;

while(a>0)

{

b=a%10;

rev=rev*10+b;

a=a/10;

}

if (rev==y)

return 1;

else

return 2;

}

boolean Prime(int m)

{

int c=0;

for(int i=1;i<=m;i++)

{

if (m%i==0)

c++;

}

if (c==2)

return true;

else

return false;

}

void main()throws IOException

{

System.out.println("Enter a 4 digit no");

int X=Integer.parseInt(br.readLine());

inputData(X);

System.out.println("Enter the same no. again");

int y1=Integer.parseInt(br.readLine());

Pal(y1);

System.out.println("Enter the same no. again");

int m1=Integer.parseInt(br.readLine());

Prime(m1);

if (Pal(y1)==1 && Prime(m1)==true)

System.out.println(x+" is a Pal-Prime No.");

else

System.out.println(x+" is not a Pal-Prime No.");

}

}

User Avatar

Wiki User

14y ago

Still curious? Ask our experts.

Chat with our AI personalities

FranFran
I've made my fair share of mistakes, and if I can help you avoid a few, I'd sure like to try.
Chat with Fran
ViviVivi
Your ride-or-die bestie who's seen you through every high and low.
Chat with Vivi
CoachCoach
Success isn't just about winning—it's about vision, patience, and playing the long game.
Chat with Coach

Add your answer:

Earn +20 pts
Q: How do you write a program in Java to check whether a number is a pal prime or not?
Write your answer...
Submit
Still have questions?
magnify glass
imp