Categories
algorithms kotlin

Problem 5.8 from EPI -> Reverse digits of a number

Given a number like “123”, print out the reverse of that number like “321”!
There is a quick and easy way, convert the number to string and call string.reverse(), but it takes more memory than is neccessary.
A better way is to repeatedly take the most right number multiply it by 10 and add the next most right number, repeat until the number to reverse is zero.
Take a look at this code.
Happy coding!

Leave a Reply

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