Monday, 5 January 2015

Java Program to check whether a number is Palindrome number or not




This is a Java program which checks whether a number is palindrome or not .
Generally a number is said to be a palindrome number if its reverse is same as the original number .

For Example : 121 is a palindrome as its reverse is also 121 where as , 231 is not a palindrome as its reverse is 132 .




PROGRAM :

package codingcorner.in;

import java.util.Scanner;

public class Palindrome {
 public static void main(String[] args) {
  int number, remainder, reverse = 0, num;
  Scanner scan = new Scanner(System.in);
  System.out.println("Enter a number :\t");
  number = scan.nextInt();
  scan.close();
  num = number;
  while (number != 0) {
   remainder = number % 10;
   reverse = reverse * 10 + remainder;
   number = number / 10;
  }
  if (reverse == num)
   System.out.println(num + "  is Palindrome");
  else
   System.out.println(num + "  is not a Palindrome");
 }
}

OUTPUT :