## Java Nested Loop Sample Problem 3

We continue our series in nested loop logic problems and we improve on the first problem we stated. We are now reversing the pattern of the triangle, and instead of showing this pattern for input 3:
*
**
***
We will show this:
*
**
***

As you can see, we are trying to gradually increase the difficulty of our problem. If we have solved the first problem, this one introduce the issue of adding space. Some more patterns, for example, given the input number 5:
*
**
***
****
*****
We sole this issue by adding a new loop inside the main loop, to add the spaces that we want.
```/**
* A simple program that outputs triangle pattern based on input.
*/
public class TriangleProgram {
public static void main(String[] args) {
drawTriangle(10);
}
private static void drawTriangle(int n) {
for (int i=1; i<=n; i++) {
for (int j=1; j<=(n-i); j++) {
System.out.print(" ");
}
for (int j=1; j<=i; j++) {
if (j==i) {
System.out.println("*");
} else {
System.out.print("*");
}
}
}
}
}
```
And the rest is the same as the solution to the first problem. Below is the output if the given number is 10.
*
**
***
****
*****
******
*******
********
*********
**********
Which is pretty cool, in the next problem, we combine problems two and three.