14. A palindromic prime is a prime number and also palindromic. For example, 131, 313, and 757 are prime numbers and
also palindromic prime numbers. Write a program that displays the first 100 palindromic prime numbers.
Answers
Explanation:
Follow the steps .
See the comment written and u might know when u find prime number and when a palindrome number.
Hope this helps you.
Have a nice day !
Answer:
Using methods
Explanation:
import java.util.*;
public class Calculate
{
int num,rev,f;
public Calculate(int n)
{
num = n;
f = 0;
rev = 0;
}
public int prime() {
int c=0;
for(int i=1;i<=num;i++)
{
if(num%i==0)
c++;
}
{
if(c==2)
f=1;
return f;
}
}
public int reverse()
{ int t=num;
while(t!=0)
{
int d= t%10;
rev= rev*10+d;
t=t/10;
}
return rev;
}
void display()
{
if(f==1 && rev==num)
System.out.println("It is a prime palindrome");
else
System.out.println("It is not a prime palindrome");
}
public static void main(String args[])
{
Scanner kb= new Scanner(System.in);
System.out.println("Enter number");
int number=kb.nextInt();
Calculate obj =new Calculate(number);
obj.prime();
obj.reverse();
obj.display();
}
}