Computer Applications
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,
Java
Java Nested for Loops
74 Likes
Answer
public class KboatPrimePalindrome
{
public void displayPrimePalindrome() {
int count = 0;
for (int i = 10; i <= 1000; i++) {
int num = i, revNum = 0;
while (num != 0) {
int digit = num % 10;
num /= 10;
revNum = revNum * 10 + digit;
}
if (revNum == i) {
boolean isPrime = true;
for (int j = 2; j <= i / 2; j++) {
if (i % j == 0) {
isPrime = false;
break;
}
}
if (isPrime) {
System.out.print(i + " ");
count++;
if (count == 10) {
System.out.println();
count = 0;
}
}
}
}
}
}
Variable Description Table
Program Explanation
Output
Answered By
30 Likes
Related Questions
Write a program in Java to enter a number containing three digits or more. Arrange the digits of the entered number in ascending order and display the result.
Sample Input: Enter a number 4972
Sample Output: 2, 4, 7, 9Write a program to input two numbers and check whether they are twin prime numbers or not.
Hint: Twin prime numbers are the prime numbers whose difference is 2.
For example: (5,7), (11,13), ……. and so on.In an entrance examination, students have been appeared in English, Maths and Science papers. Write a program to calculate and display average marks obtained by all the students. Take number of students appeared and marks obtained in all three subjects by every student along with the name as inputs.
Display the name, marks obtained in three subjects and the average of all the students.Write a program to display all the numbers between 100 and 200 which don't contain zeros at any position.
For example: 111, 112, 113, ……. , 199