tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Articles > Java > Coding Examples > Palindrome Number

Palindrome Number 

Verify whether a given number is Palindrome number.

File Name  :  
com/bethecoder/tutorials/coding/examples/PalindromeNumberTest.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.coding.examples;

public class PalindromeNumberTest {

  /**
   @param args
   */
  public static void main(String[] args) {
    System.out.println(isPalindrome(123456));
    System.out.println(isPalindrome(1234321));
    
    System.out.println(isPalindrome(1010));
    System.out.println(isPalindrome(10101));
  }

  private static boolean isPalindrome(int num) {
    return num == reverseNumber(num);
  }
  
  private static int reverseNumber(int num) {
    int sum = 0;
    while (num > 0) {
      sum = (sum * 10(num % 10);
      num = num/10;
    }
    return sum;
  }
}
   

It gives the following output,
false
true
false
true



 
  


  
bl  br