New to recursion. The output of this code is 79, How is this answer reached? When written down I find the base case never being reached. (-3+4) + (2 * -3) = -5 => (-5+4) + (2 * -5) = -11... Do I have a fundamental misunderstanding of recursion or basic algebra?
int result = negative(-3);
public int negative(int num)
{
if(num >= 20)
{
return -5;
}
else
{
return negative(num + 4) + 2 * num;
}
}
public void print()
{
System.out.println("The final answer is " +result);
}
negative(num + 4) + (2 * num)notnegative((num + 4) + (2 * num)).