Posted by

What is a Palindrome Number?

A palindromic number or palindrome number is a number that remains the same when its digits are reversed. Like 16461.

Logic For Palindrome:

After understanding the meaning of palindrome number, its get easier for us to build a program to check whether a number is palindrome or not? So, as per the above definition we will take a number and than check if it remains same after getting reversed! so, the main logic behind this program is to take a number(input) and reverse it and than compare the reversed number with the number at the time of input. Lets see how to do it...
Source Code:
/* Palindrome Program In JAVA
  © Code Nirvana (www.codenirvana.in)
import java.util.Scanner;
class Palindrome{ 
     public static void main(String args[]){ 
       System.out.print("Enter Number: ");
       Scanner read = new Scanner(System.in);
       int num = read.nextInt();
       int n = num;
       //reversing number
       int rev=0,rmd; 
       while(num > 0) 
         rmd = num % 10; 
         rev = rev * 10 + rmd; 
         num = num / 10; 
       if(rev == n) 
         System.out.println(n+" is a Palindrome Number!"); 
         System.out.println(n+" is not a Palindrome Number!"); 

Palindrome Output - Code Nirvana

Tutorial: Palindrome Program In Java

{ 3 comments... read them below or Comment }

  1. explain me in detail code for palindrome

    1. The above article explains about palindrome and its code in detail!
      What you want to know, or which part you didn't understand?

  2. This comment has been removed by a blog administrator.


Search Site


Back To Top