A recursive method may call other methods, including calling itself. A recursive method has:
1. a base case -- a case that returns a value or exits from a method without performing a recursive call.
2. a recursive case -- calling the method again with a smaller case..
Study the recursive method given below.
For example, this call recursiveMethod (5); returns 15:
public static int recursiveMethod (int num) (
if (num == 0)
return 1;
else {
if (numX2!=0)
return num * recursiveMethod (num -1);
else
return recursiveMethod (num-1);
}
}
1 What is the base case?
2. What does the following statement check?
3. What does the method do?

Respuesta :

Answer:

Hence the answer is given as follows,

Explanation:

Base Case:-  

If (num == 0) //This is the base case for the given recursive method  

return 1;  

If(num % 2!=0) checks whether num is odd.  

The above condition is true for all odd numbers and false for even numbers.  

if the remainder is not equal to zero when we divide the number with 2 then it is odd.  

The method:-  

The above recursive method calculates the product of odd numbers up to the given range(that is num)  

For num=5   => 15(5*3*1).  

For num=7   => 105(7*5*3*1).  

For num=10 => 945(9*7*5*3*1).