Consider the getArea method from the book shown below.
Public int getArea()
{
If (width <= 0) { return 0; } // line #1
Else if (width == 1) { return 1; } // line #2
Else
{
Triangle smallerTriangle = new Triangle(width - 1) ; // line #3
Int smallerArea = smallerTriangle.getArea() ; // line #4
Return smallerArea + width; // line #5
}
}
Assume lines #1 and #2 were changed to this:
If (width == 1) { return 1; } // new line #1-2
What will happen when this code is executed?
A) A negative or zero width would cause problems.
B) Nothing - the method would still be correct.
C) We would lose our only recursive case.
D) A positive width would reduce the correct area by 1.
Correct Answer:
Verified
Q1: Consider the following code snippet for calculating
Q3: Consider the recursive method myPrint shown in
Q4: Consider the getArea method from the textbook
Q5: Consider the following recursive code snippet:
Public int
Q6: Consider the getArea method from the textbook
Q7: Consider the code for the recursive method
Q11: Consider the recursive method shown below:
Public static
Q12: Consider the getArea method from the textbook
Q13: Consider the recursive method myPrint:
Public void myPrint(int
Q17: What is required to make a recursive
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