Could someone explain to me what it returns?

int result2 = negative(-3);       System.out.println("The final answer is " + result2);

       [B]public[/B] [B]int[/B] negative(int num){
         [B]if[/B](num >= 20){
           [B]return[/B] -5;
         }[B]else[/B]{
           [B]return[/B] negative(num + 4) + 2 * num;
         }
       }
Member Avatar for iamthwee

Try drawing a flow chart for your code.

Then choose an arbitary starting value. And go through changing each value so they obey each condition. Eventually you'll get to stage where you have to stop and that's your end value.

Recursion, is just a function which calls itself from within itself. A rather crude definition but you get the point.

thanks but sometimes look at last active Date

Nov 25th, 2006

:-)

He might have just been hanging around waiting for an answer all this time...

lol...;)

May be now he is the software engineer.......
:D

why not, nobody knows, maybe we'll ask her/his for job on tomorow :-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.