![]() |
|
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Hobbyist Programmer
|
Debug recursion method()
Hi guys,
I need your expertice to debug my recursion method... Here is the problem: I am trying to figure out how come my code is not working properly. The design and algorithm are correct but it seem that the recursion method did not fully return the whole value that passed. I have two different recursion method but both of them are not returning the rest of the value . below is the code: 1st recursion method public static int reverseDigit(int num)
{
int reverseNum = 0;
if(num > 0)
{
reverseNum = reverseNum *10 + num % 10;
return reverseDigit(num/10);
}
else
return reverseNum;
}2nd Recursion method public static int reverseDigit(int num)
{
int reverseNum = 0;
if(num < 0)
{
return reverseNum;
}
else{
reverseNum = reverseNum *10 + num % 10;
return reverseDigit(num/10);
}
}Thank you for your help in advance.
__________________
-- pr0gm3r |
|
|
|
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|