8) Consider the getArea method from the textbook 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 the code in line #3 is changed to: Triangle smallerTriangle = new Triangle (width);
Added by Kristin A.
Close
Step 1
Step 1: The change in line #3 means that the new smallerTriangle will have the same width as the original triangle. Show more…
Show all steps
Your feedback will help us improve your experience
Supreeta N and 92 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Write a program in Java to create a pattern of a right angle triangle with numbers increasing by 1. The size of the triangle is determined by the number of rows specified by the user. For example, if the user chooses to print a right triangle with 3 rows, the program should output: 1 2 3 4 5 6 If the user chooses to print a right triangle with 4 rows, the program should output: 1 2 3 4 5 6 7 8 9 10
Supreeta N.
Text: 11.14 LAB: Drawing a right side up triangle Write a recursive function called DrawTriangle() that outputs lines of '*' to form a right-side-up isosceles triangle. The function DrawTriangle() has one parameter, an integer representing the base length of the triangle. Assume the base length is always odd and less than 20. Output 9 spaces before the first '*' on the first line for correct formatting. Hint: The number of '*' increases by 2 for every line drawn. Ex: If the input of the program is: 3 the function DrawTriangle() outputs: * *** Ex: If the input of the program is: 19 the function DrawTriangle() outputs: * *** ***** ******* ********* *********** ************* *************** ***************** ******************* Note: No space is output before the first '*' on the last line when the base length is 19. #include <iostream> using namespace std; /* TODO: Write recursive DrawTriangle() function here. */ int main() { int baseLength; cin >> baseLength; DrawTriangle(baseLength); return 0; }
Akash M.
17.1 LAB: Drawing an upside-down triangle Write a recursive method called drawTriangle() that outputs lines of '*' to form an upside-down isosceles triangle. The method drawTriangle() has one parameter, an integer representing the base length of the triangle. Assume the base length is always odd and less than 20. Output 9 spaces before the first '*' on the last line for correct formatting. Hint: The number of '*' decreases by 2 for every line drawn. Ex: If the input of the program is: 3 the method drawTriangle() outputs: *** * Ex: If the input of the program is: 19 the method drawTriangle() outputs: ******************* ***************** *************** ************* *********** ********* ******* ***** *** * Note: No space is output before the first '*' on the first line when the base length is 19.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Transcript
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD