## Java Nested Loop Sample Problem 4

The fourth problem we wish to give is again an enhancement of the first problem in this series that also draws a triangle. This time, we wish to draw an inverted triangle as shown below for input number 5:
*****
****
***
**
*

Below is another example of what we want to achieve when given input 7.
*******
******
*****
****
***
**
*
Below is the solution:
```/**
* A simple program that outputs triangle pattern based on input.
*/
public class TriangleProgram {
public static void main(String[] args) {
drawTriangle(7);
}
private static void drawTriangle(int n) {
for (int i=n; i>=1; i--) {
for (int j=1; j<=i; j++) {
if (j==i) {
System.out.println("*");
} else {
System.out.print("*");
}
}
}
}
}
```
The solution to this problem is very similar on how we solved the first problem, we just inverted how we loop the first loop in the solution. We started from the largest going to the lowest. Below is another sample output for input number 10:
**********
*********
********
*******
******
*****
****
***
**
*
Enjoy solving!