Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Oct 11th, 2005, 4:21 AM   #1
pr0gm3r
Hobbyist Programmer
 
Join Date: Dec 2004
Location: CA
Posts: 102
Rep Power: 4 pr0gm3r is on a distinguished road
Send a message via MSN to pr0gm3r
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
pr0gm3r is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:32 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC