rss
Twitter Delicious Facebook Digg Stumbleupon Favorites

Saturday, October 8, 2011

A program to find whether number is palindrome or not.

A palindromic number or numeral palindrome is a 'symmetrical' number like 16461, that remains the same when its digits are reversed. The term palindromic is derived from palindrome, which refers to a word like rotor that remains unchanged under reversal of its letters. The first palindromic numbers (in decimal) are:

0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99, 101, 111, 121, 131, 141, 151, 161, 171, 181, 191, ….
Palindromic numbers receive most attention in the realm of recreational mathematics. A typical problem asks for numbers that possess a certain property and are palindromic. For instance,
  • the palindromic primes are 2, 3, 5, 7, 11, 101, 131, 151, …
  • the palindromic square numbers are 0, 1, 4, 9, 121, 484, 676, 10201, 12321, …
Buckminster Fuller referred to palindromic numbers as Scheherazade numbers in his book Synergetics, because Scheherazade was the name of the story-telling wife in the 1001 Nights.
It is fairly straightforward to appreciate that in any base there are infinitely many palindromic numbers, since in any base the infinite sequence of numbers written (in that base) as 101, 1001, 10001, etc. (in which the nth number is a 1, followed by n zeros, followed by a 1) consists of palindromic numbers only.
Although palindromic numbers are most often considered in the decimal system, the concept of palindromicity can be applied to the natural numbers in any numeral system. Consider a number n > 0 in base b ≥ 2, where it is written in standard notation with k+1 digits ai as:
n=\sum_{i=0}^ka_ib^i
with, as usual, 0 ≤ ai < b for all i and ak ≠ 0. Then n is palindromic if and only if ai = aki for all i. Zero is written 0 in any base and is also palindromic by definition.
class PalindromeNumbers{
      public static void main(String args[]){
          int num = Integer.parseInt(args[0]);
          int n = num;
          int reverse=0,remainder;
          while(num > 0){
                remainder = num % 10;
                reverse = reverse * 10 + remainder;
                num = num / 10;
           }
          if(reverse == n)
              System.out.println(n+" is a Palindrome Number");
          else
              System.out.println(n+" is not a Palindrome Number");
     }
}

1 comments:

Saroja Patra said...

u r so fantastic.any how thank u very much

Post a Comment

Powered by Blogger.