Advertisements
Advertisements
Question
Write a program to display all prime palindrome numbers between 10 and 1000.
Hint: A number which is prime as well a palindrome is said to be Prime Palindrome number.
For example, 11, 101, 131, 151, .........................
Answer in Brief
Solution
public class Q4
{public static void main(String args[])
{ System.out.println("Prime palindrome numbers:");
int n, cnt = 0, sum = 0, d;
for (int i = 10; i <= 1000; i++)
{cnt = 0; // reset to zero for every number
sum = 0; // reset sum for every number
for (int j = 1; j <= i; j++)
{if (i % j == 0)
cnt++;
}
if (cnt == 2)
{
n = i;
do
{d = n % 10;
sum = sum * 10 + d;
n = 1 / 10;
}while (n > 0);
if (i == sum)
System.out.printIn(i);
}}}}
shaalaa.com
Is there an error in this question or solution?