In: Computer Science
1. When a method definition contains an invocation of itself, the method is said to be _________.
2. When a method definition contains an invocation of itself, the method is said to be _________.
3. True or False. A recursive method needs to have an if-else or other branching leading to different cases.
4. True or False. A recursive method should only contain one call to itself.
Hi, the question number 1 and 2 are same so I'm just answering them once only.
1) the answer for question number 1 is recursion method. Recursion methods are referred as the methods that calls themselves. It provides a method to break complicated problems by breaking them into parts and making them easy. The example for adding numbers by recursion is -
a=10
public static int sums(int a) {
if (a > 0) {
return a + sums(a - 1);
} else {
return 0; }}
2) the answer is True. It's Beacuse if there will be no branching it will go on an infinite loop as there will be no condition when to come out of the function or return some value.
3) the answer for this question is True. The term recursive means repeating something so if in case you call any other function inside other than the same function it'll no longer remain a recursive function or method. For it to be recursive it has to call itself only.