Problem calling method rec

folks here's a look at my code

public Date getBusinessDate(Date start , Date end )

{

int days = 0;

Calendar startcal = Calendar.getInstance();

startcal.setTime(start);

while(startcal.getTime().getTime() < end.getTime())

{

startcal.add(Calendar.DATE,1);

int day = startcal.get(Calendar.DAY_OF_WEEK);

if( day == Calendar.MONDAY || day == Calendar.TUESDAY || day == Calendar.WEDNESDAY ||

day == Calendar.THURSDAY || day == Calendar.FRIDAY)

{

continue;

}

days++;

}

startcal.add(Calendar.DATE , (days));

Date recursiveEnd = startcal.getTime();

if(days > 0)

{

getBusinessDate(end , recursiveEnd);

}

System.out.println("The date is"+recursiveEnd);

return (recursiveEnd);

}

what I am trying to do here is trying to pass on 2 dates to this method which in turn will return me result date which takes into account the weekends and does not count the weekends (it just counts the business days).

I am calling the function again at the end to make sure that the days added to startcal object does not have a weekend again.

my output with the final println is

The date isMon Jan 01 09:44:43 GMT-05:00 2007

The date isMon Jan 01 09:44:43 GMT-05:00 2007

The date isSun Dec 31 09:44:43 GMT-05:00 2006

The date isSat Dec 30 09:44:43 GMT-05:00 2006

i do not have the println in a loop and it still prints 4 times why?

jan 01 is the date it shld be returnin then why is it returnin dec 30?

thanks a lot for your patience

[1628 byte] By [redpunta] at [2007-11-26 13:17:37]
# 1
getBusinessDate invokes itself. So actually you do have the println in a loop of sorts - recursion.
warnerjaa at 2007-7-7 17:41:50 > top of Java-index,Java Essentials,Java Programming...
# 2

yeah i understand that but why is returnin me the date dec 30 instead of jan1 which I am expecting when I call this function from somewhere else. you mean to say the return in the end is invoked the number of times getBusinessDays is called?

i guess i have a hint of the above but waitin to hear from you guyz and what could be a probable solution to the above?

redpunta at 2007-7-7 17:41:50 > top of Java-index,Java Essentials,Java Programming...
# 3
> getBusinessDate(end , recursiveEnd);Try this:recursiveEnd = getBusinessDate(end, recursiveEnd);Other than that, I'd suggest you take an iterative (loop) approach to this rather than a recursive one. This design smells of not being appropriate for recursion.
warnerjaa at 2007-7-7 17:41:50 > top of Java-index,Java Essentials,Java Programming...
# 4
looks like the above suggestion is working.my sincere thanks but can you explain me why it is working....i knw not the best question but if you can provide me with a small hint i wld be grateful
redpunta at 2007-7-7 17:41:50 > top of Java-index,Java Essentials,Java Programming...