is there an algorithm to reverse a chosen part of a number? [closed]

Reversing part of a number or entire number is not a math operation that can be done with Integers/Longs, so you can use Strings.

Convert your number to a StringBuilder, there is a reverse() method there.
You can cut the String with substring() method also. After cutting and reversing, concatenate again.

EDIT: It can be done with just numbers that way:

Step 1 — Isolate the last digit in number:

lastDigit = number % 10

Step 2 — Append lastDigit to reverse

reverse = (reverse * 10) + lastDigit

Step 3 – Remove last digit from number

number = number / 10

Step 4 – Iterate this process

while (number > 0)

Source: https://medium.com/@ManBearPigCode/how-to-reverse-a-number-mathematically-97c556626ec6

Leave a Comment