Search

Google
 

Wednesday, January 23, 2008

Write a java program that checks whether a given NUMBER is palindrome or not.

Write a java program that checks whether a given NUMBER is palindrome or not.


import java.io.*;
public class Palindromenumber
{
public static void main(String args[])throws IOException
{
DataInputStream din=new DataInputStream(System.in);
int num,remainder,result=0,n;
System.out.println("Enter the number:");
String s=din.readLine();num = Integer.parseInt(s);
n=num;
while(num>0)
{
remainder = num%10;result = result * 10 + remainder;num = num/10;
}
if(n==result)
{
System.out.println(n+"is palindrome" );
}else
{
System.out.println(n+" is not palindrome" );
}
}
}

No comments: