How to reverse digits in a number in Java – How to find if a number is a palindrome in java

In java, sequence of digits in a number can be reversed by performing division and modulo operations on the given number. Below is the code snippet in Java to achieve the same:

Output of this program would be:
revNum: 54321

The same code snippet can be used to find out if the given number is a palindrome. To check that, below code snippet needs to be added after the System.out.println statement.

Please let us know if there are better way of doing the things.

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">