Tim Driven Development | Test until the fear goes away
The code works great minus the fact that if I input a number that begins with zero, the output will drop the zero.
Tim Cooke wrote:You will of course have to think of another way to reverse the characters.
Derik Davenport wrote:And if you decide to reverse the string (before it become an int) then the StringBuilder class has a useful reverse() function.
I didn't assume that this was homework and not self learning. But since I couldn't rule that out I also suggested the Integer.parseInt() function. With that he can solve this with minimal changes to his reverseDigits() method.Tony wrote: unfortunately if this is homework then I'd imagine using StringBuider won't be allowe
Derik Davenport wrote:Now you can pass inputNum and the inputString (or at least a number representing inputString.length) into the reverseDigits method. If the final result of reveseDigits() doesn't have as many digits as inputString has characters, then you know that there were leading zeros.
OCAJP Java 8, OCPJP Java 8
Jeff Boynton wrote:Would it make more sense to just set this up using strings?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Would anybody like some fudge? I made it an hour ago. And it goes well with a tiny ad ...
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|