Write a class program with the following specifications:
Class name: Calculate
Instance variables: int num, f, rev
Member Methods:
Calculate (int n): to initialize num with n, f and rev with 0 (zero)
int prime(): to return 1, if number is prime
int reverse(): to return reverse of the number
void display(): to check and print whether the number is a prime palindrome or not
Answers
Answered by
46
Answer:
class Calculate
{
int num;int f;int rev;
Calculate(int n)
{num=n;
f=0;
rev=0;}
int prime(int k)
{int c=0;
for(int i=1;i<=k;i++)
{if((k℅i)==0)
{c++;}}
int p=0;
if (c=2){
p=1;}
return p;}
int reverse(int k)
{int z=0;int c=num;
while(c>0)
{ int d=c℅10;
z=z*10+d;
c=c/10;}
return z;}
void display()
{int i=reverse(num);
int j=prime (num);
if(j==1 && i==num)
{ System.out.println("Pallindrome Number");}
else
{
System.out.println("Not A Pallindrome Number");}
}
void main(int q)
{ Calculate obj=new Calculate(q);
obj.display();}
}
Similar questions