###
**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:**

**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!"); else System.out.println(n+" is not a Palindrome Number!"); } }

**Output:**

####
**Tutorial: Palindrome Program In Java**

explain me in detail code for palindrome

ReplyDeleteThe above article explains about palindrome and its code in detail!

DeleteWhat you want to know, or which part you didn't understand?

This comment has been removed by a blog administrator.

ReplyDeletesir , please explain 12 and 16 line in detail .thankyou in advance

ReplyDeleteWell before explaining I will suggest you to first run this program on paper (manually) for better understanding of the logic used!

DeleteHere, rev is for reverse and rmd for remainder.

In line 12 we created two variables rev and rmd of int type.

and in line 16 we are assigning values to variable rev in every run. here's the explanation:

rev = rev * 10 + rmd;

suppose your no. is 12,

In the first run rmd = 2 and rev = 0*10 + 2 == 2

in second run rmd = 1 and rev = 2*10 + 1 == 21

and in the third run our condition becomes false and loop breaks!

Than the reverse of 12 is 21 , which is the required result....

Hope you got our point, for more help feel free to contact us!

Thanks for the explanation! :)

ReplyDeleteOur pleasure! Keep Visiting.....

Deletei cant understand same example plzzzz help me

ReplyDeleteplease be specific about your problem, which example you didn't understand?

Deletesir can you explain me the full logic of palindrome how it is done?

ReplyDeletePalindrome is just a number which remains the same on reversing it! So the logic is same as Reverse Number and further we just compared the reversed number with the input!

DeleteHope this helps to get the logic behind this!

sir, pls explain form 10 to 19 line

ReplyDeleteNumber reversing process is done there! nothing much to explain... check reverse number post @ our blog.

Deletepalindrome is means to check it can reverse, so we getting number after dat we createing input after i cant understand.. pls help me wat logic s going inside it to check palinderome or nor pls help me

ReplyDeleteFirst input number, make a copy of that num variable to variable n, apply reverse number logic to n and store reversed number in variable rev, finally check whether rev == num.... if condition is true means palindrome otherwise not!

DeleteHope this gives you better understanding about the logic and program concept!

Thanks sir, i understand ... thanks vry much for instead if scanner why we cannot use DataInputStream obj= new DataInputStream(System.in);

ReplyDelete