How to Reverse a Number in Java

In this post we’ll see how to reverse a number in Java. The Java program to reverse a number can be written in both iterative as well as recursive way. Both solutions are given here.
Logic for both of the method is similar; you need to do a modulo division by 10 to get the last digit and using that remainder you need to create the reversed number. In iterative method this will be done in a loop where as in a recursive method you will call the method again after removing the last digit.

Java code to reverse a number – Iterative and Recursive


That’s all for the topic How to Reverse a Number in Java. If something is missing or you have something to share about the topic please write a comment.

You may also like

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.