Q :- WAP to define a class with following functions
(i) void input (int) - to input a number
(ii)void check ()- to check whether it
is palindrome or not.
(iii) void disp ()- to display the
result
Answers
Answered by
1
Answer:
class PalindromeCheck{
int n;
boolean b;
void input (int input){
n=input;
}
void check(){
int n1 = n;
int s=0;
while(n1>0){
s = s*10 + n1%10;
n1 = n1/10;
}
if(s==n)
b=true;
else
b=false;
}
void disp(){
if(b==true)
System.out.println("Palindrome");
else
System.out.println("Not a Palindrome");
}
}
It is written in BlueJ environment
Similar questions