Write a recursive method called drawTriangle() that outputs lines of '*' to form an upside down isosceles triangle. 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.
Write a recursive method called drawTriangle() that outputs lines of '*' to form an upside down isosceles triangle. 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
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.
![### Lab Activity: Drawing an Upside Down Triangle
#### Java Programming Example
In this lab, the task is to draw an upside-down triangle using a recursive method in Java. Below is a partial implementation where you'll need to complete the missing `drawTriangle()` method.
```java
import java.util.Scanner;
public class LabProgram {
/* TODO: Write recursive drawTriangle() method here. */
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
int baseLength;
baseLength = scnr.nextInt();
drawTriangle(baseLength);
}
}
```
#### Explanation
- **Import Statement**: The `Scanner` class is imported to allow taking inputs from the user.
- **Class Definition**: The `LabProgram` class encapsulates the logic for this exercise.
- **TODO Comment**: A placeholder is provided for the recursive method `drawTriangle()`. You will need to implement this method to draw the pattern.
- **Main Method**:
- Initializes the `Scanner` object to read input from the console.
- Reads an integer value `baseLength` which determines the base length of the triangle.
- Calls the `drawTriangle()` method with `baseLength` as an argument.
This lab requires you to write a recursive function to display an upside-down triangle pattern based on the user-provided `baseLength`.
Make sure to implement the logic for the `drawTriangle()` function to complete the lab activity.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F9e6fa127-a003-469d-9a51-b1d4610918ed%2Fdac6539c-24b1-4597-9793-1fe42b884fdd%2F8dwqn7u_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 3 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)