In: Computer Science
JAVA RECURSION public void recMethod(int[] array, int start, int end) { if(start < end) { print the array double the value in the array at position start recMethod(array, start+1, end) print the array } else { print "done" } }
Assume the method is invoked with array = [3, 4, 6, 7, 8, 10, 4], start = 2, and end = 5
1.How many times is the array printed before the word "done" is printed?
2.How many times is the array printed after the word "done" is printed?
3.Which of the following is true?
a.The contents printed in the line directly before the "done" are the same as the contents printed in the line directly after the "done."
b.There is nothing printed out after the "done."
c.The contents printed in the line directly before the "done" are different from the contents printed in the line directly after the "done."
4.Which of the following is true?
a.All array print outs after the "done" show the same contents as each other.
b.The array print outs after the "done" are not all the same.
c.There are no array print outs after the "done."
Answer 1 : Three times array get printed before word "done" get printed.
Answer 2 : Three times array get printed after word "done" get printed.
Answer 3 : (a) . FALSE , no contents printed in the line directly before the "done" are different as the contents printed in the line directly after the "done."
(b) . FALSE, there are three line printed after word "printed".
(c). TRUE, yes contents printed in the line directly before the "done" are different from the contents printed in the line directly after the "done" at 4th index.
Answer 4 : (a) TRUE, all arrays printed after "done" have same content.
(b) FALSE,no all the array printed after "done" have same content.
(c) FALSE,there are three array printed out after the "done."
For better clearity,i i will suggest you to dry run the code once you will be all clear.
If any doubt in solution let me know through comments.
Thanks.