A. Consider the square() method shown below that takes a non-negative int argume
ID: 3707729 • Letter: A
Question
A. Consider the square() method shown below that takes a non-negative int argument. Complete the code for the square() method so that it correctly calls the squareHelper() method to produce the square of n.
B. Consider the permutations() method from the textbook, which is intended to return all permutations of the word passed in as a parameter. How does the permutations() method simplify its input for the recursive call?
C. Consider the getArea() method from the textbook shown below.
Where is/are the recursive call(s)?
D. Consider the helper method reversePrint, which uses recursion to display in reverse the elements in a section of an array limited by the firstIndex and lastIndexarguments. What statement should be used to complete the recursive method?
1. return squareHelper(n, n - 1)Explanation / Answer
A
3. return squareHelper(n, n)
Adding n for n time gives it's square
B
4. It finds permutations of shorter words formed by removing the ith character.
word.substring(0, i) + word(substring(i + 1)) means substring from 0 to i-1 and i+1 to end
C
3. line #6
Recursive call means calling the method itself. smallerTriangle.getArea(); is calling itself.
D
2. array[firstIndex]
Calling recursively and then printing.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.