wap to accept and check wheather it a palindrome or not by using method void palin(int)
Answers
The given code is written in Java.
import java.util.*;
public class CheckPalindrome{
void palin(int a){
int b=a,s=0;
for(;b!=0;b/=10)
s=s*10+b%10;
if(s==a)
System.out.println(a+" is Palindrome number.");
else
System.out.println(a+" is not a Palindrome number.");
}
public static void main(String s[]){
Scanner sc=new Scanner(System.in);
CheckPalindrome obj=new CheckPalindrome();
System.out.print("Enter a number: ");
int a=sc.nextInt();
obj.palin(a);
}
}
Here, the palin() method checks whether a number is palindrome or not. This function is called in main() method after taking the number as input.
Note: You can also write this -
System.out.print("Enter a number: ");
(new CheckPalindrome()).palin(sc.nextInt());
A palindrome number is a number which remains unchanged when read from backward side. Example: 121, 1221, 12321 etc..