Consider the getArea method from the textbook shown below: public int getArea()
{
If (width <= 0) { return 0; } // line #1
If (width == 1) { return 1; } // line #2
Triangle smallerTriangle = new Triangle(width - 1) ; // line #3
Int smallerArea = smallerTriangle.getArea() ; // line #4
Return smallerArea + width; // line #5
}
Assume line #3 is changed to this:
Triangle smallerTriangle = new Triangle(width + 1)
When calling the getArea method on a Triangle object with width = 4, what result will be produced?
A) area for all triangles will be computed to be too high
B) area for all triangles will be computed to be too low
C) area will only be incorrect for a triangle objects with width = 1
D) infinite recursion will occur for triangle objects with width >= 2
Correct Answer:
Verified
Q21: Which of the following options could be
Q22: A recursive method without a special terminating
Q23: If a recursive method does not simplify
Q24: Consider the method below, which implements the
Q25: Consider the getArea method from the textbook
Q27: Would switching the special case order affect
Q28: How many recursive calls to the fib
Q29: _ recursion can occur when a recursive
Q30: If recursion does not have a special
Q31: Consider the problem of arranging matchsticks so
Unlock this Answer For Free Now!
View this answer and more for free by performing one of the following actions
Scan the QR code to install the App and get 2 free unlocks
Unlock quizzes for free by uploading documents