Friday, 3 June 2016
Java Program to Reverse an Integer Number without using String - Example
When I was asked "Can you write a program to reverse a number in Java" long long years back, I did a trick. I converted the number to String by just concatentating with empty String e.g. "" + 123 and then converted that Stirng to StringBuilder can caled 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.
Subscribe to:
Posts (Atom)