About Me

My photo
Raipur, Chhattisgarh, India
Hi , I am Amit Thakur. I have worked as a QA Engineer for two years and as a Java Developer for one year in NIHILENT TECHNOLOGIES PVT. LTD., Pune.Currently I am working as DEAN (Research & Development) in Bhilai Institute of Technology, Raipur.

Saturday, July 23, 2011

***Palindrome Checking for Numbers***


import java.io.*;

public class Palindrome
{
public static void main(String [] args)
{
  try
{
  BufferedReader object = new BufferedReader(new InputStreamReader(System.in));
  System.out.println("Enter number");
  int num= Integer.parseInt(object.readLine());
  int n = num;
  int rev=0;
  System.out.println("Number: ");
  System.out.println(" "+ num);
  for (int i=0; i<=num; i++)
{
  int r=num%10;
  num=num/10;
  rev=rev*10+r;
  i=0;
  }
  System.out.println("After reversing the number: "+ " ");
  System.out.println(" "+ rev);
  if(n == rev)
{
  System.out.print("Number is palindrome!");
  }
  else
{
  System.out.println("Number is not palindrome!");
  }
  }
  catch(Exception e)
{
  System.out.println("Out of range!");
  }
  }
}


No comments: