answersLogoWhite

0


Best Answer

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

13y ago
This answer is:
User Avatar

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
Related questions

How do you find prime numbers between 2 and 70?

You can check each individual number, whether it is a prime number. For numbers below 100, it is enough to check whether they are divisible by 2, by 3, by 5, and by 7. If a number is divisible by none of these, it is a prime number.


With a given big integer number which is the product of two prime numbers how do you find them?

First write a program to generate the prime number. After one prime number was generated, divide the big int number by the prime number. If the remainder is zero then quotient is the second prime number ( also it is important to check whether the quotient is prime number or not because sometimes you will get wrong answer). Repeat the process until you get the result.


Write a java programme to check whether the number is twin prime or not?

Find a prime number, add 2 to the number. Check if the new number is prime. IE : 3 is prime. 3+2 =5. 5 is prime. (3,5) are twin primes.


Does any whole number multiply to get 29?

29 is a prime number, meaning it has no smaller factors. For any number up to 120, to check whether it is prime or not, it is sufficient to check whether it is divisible by the first four prime numbers (2, 3, 5 and 7).


How do you find Number of prime numbers below certain number?

You just have to work out it,take each number below it and check whether it is prime or not.


How can you tell whether za number is prime?

A number is prime if it only has two distinct factors.


What is the largest prime number must you check to know whether or not 667 is a prime number?

It is 29 because 29*23 = 667


Write an algorithm to check whether a number is a prime number or not?

You can write out this algorithm. This will then be programmed into the device to make determining prime numbers easier.


Algorithm to find prime numbers below ten?

Take each number in turn, call it "n", and check whether it has any factors f, such that 1 < f < n. If it doesn't, it is a prime number.Take each number in turn, call it "n", and check whether it has any factors f, such that 1 < f < n. If it doesn't, it is a prime number.Take each number in turn, call it "n", and check whether it has any factors f, such that 1 < f < n. If it doesn't, it is a prime number.Take each number in turn, call it "n", and check whether it has any factors f, such that 1 < f < n. If it doesn't, it is a prime number.


How do you know twin prime number?

You take two consecutive odd numbers and check both of them to see whether they are prime or not.


Draw a flow chart to check whether a given number is prime or not?

[object Object]


How can you check whether a number is prime or not by a C program using functions?

#include&lt;iostream.h&gt; #include&lt;conio.h&gt; void prime(int n) { clrscr(); int num; cout&lt;&lt;"enter the numbers"&lt;&lt;endl; cin&gt;&gt;num; prime(num); getch(); } void prime(int n) { int prime=1,i; for(i=2;i&lt;=n/2;i++) if(n%i==1) prime=0; if(prime==1) cout&lt;&lt;"the number"&lt;&lt;n&gt;&gt;"is prime"; else cout&lt;&lt;"the number"&lt;&lt;n&lt;&lt;"is not prime"; }