✏️ Explanatory Question
[Recursion]
Question:
Following method is a part of a class MyArray.
int check(int m[ ], int i)
{
if(i <= 0)
{
return 0;
}
return check(m, i-2) + m[i-1];
}
public static void main()
{
int m[ ] = {1, 2, 3, 4};
int ans = check(m, m.length);
System.out.println(ans);
}
(a) Predict the output of the code considering there is no compilation error. Show the working.
(b) Considering the if condition is changed to if(i < 0),
how will it affect the output?