System_Error, I came up with something similiar to yours, I think:
I know it's probably not best, but oh well.Code:public int revDigits (int num) { if (num < 10) { return num; } else { int lastDigit = num % 10; int revSeq = revDigits(num / 10); // Following code counts digits in lastDigit int j = revSeq; int c = 0; while (j != 0) { j = j / 10; c++; } return (lastDigit * (int)Math.pow(10, c)) + revSeq; } }
CB, all of the recursion problems he gave us are better to accomplish without recursion.
Thanks for your help, guys.




Reply With Quote