0

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;
         }
       }

Edited by happygeek: fixed formatting

5
Contributors
5
Replies
7
Views
10 Years
Discussion Span
Last Post by mKorbel
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.