Palindrome


/*Write a program to input a number.Find the sum of digits of the number and also check whether the number is a palindrome or not
 */
import java.io.*;
class palindrome
{
public static void main() throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a number");
int n=Integer.parseInt(br.readLine());
int d,p=0,s=0,h=n;  
do
{
d=n%10;
s=s+d;
p=p*10+d;
n=n/10;
}
while(n!=0);
System.out.println("The sum of the digits of the given number = "+s);
if(p==h)
System.out.println("The number is a palindrome");
else
System.out.println("The number is not a palindrome");
}
}    

Comments

Post a Comment

Popular posts from this blog

Automorphic number

Bubble sort

Prime number