How to reverse an Integer Number without using String in Java? [Solved]

Can you reverse an integer number like 1001 without using String? I am going to share a cool trick in this tutorial to do that and solve many coding problems like this

Soma
Javarevisited

--

Photo by AltumCode on Unsplash

Hello folks, when I was asked "Can you write a program to reverse a number in Java" during a coding interview last year, I was lost for a moment as I have practiced String and array reversal but not the numbers, but then I used a trick.

I converted the number to String by just concatenating with empty String e.g. "" + 123 and then converted that String to StringBuilder can called the reverse() method.

That solved the problem but Interviewer was not satisfied. He said OK, but then asked again, can you reverse a number without using anything String or StringBuilder and by building your logic with basic programming elements.

I was confused, what do you mean by basic programming elements? He said, I can use loop, if block, operator, and other basic stuff which makes a programming language.

Unfortunately, I couldn't solve the problem that day because I didn't knew the trick that

--

--