## Java Nested Loop Sample Problem 2

For the series of drawing triangles using nested loop, we present our second problem that enhances the first problem in this post. This also accepts a number and draws a triangle pattern accordingly. Below is what should be shown when the number input is 5:
1
23
456
7890
12345

This is exactly the same as the first problem, but instead of showing asterisks, we show the last digit of the ascending numbers in the series. Below are more samples if we are given the input 1, 2, and 3:
1
Above, since the input is 1 and the number sequence starts from 1, we get the output above.
1
23
When given number 2, we add a new line with two items that represents the next sequence.
1
23
456
And above is the natural next sequence of numbers. A solution to this problem is given below:
```/**
* 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) {
int number = 1;
for (int i=1; i<=n; i++) {
for (int j=1; j<=i; j++) {
if (j==i) {
System.out.println((number++)%10);
} else {
System.out.print((number++)%10);
}
}
}
}
}

```

The solution is very similar to the first problem, we just introduce a counter that we display. Below is the output when run with input 10.
1
23
456
7890
12345
678901
2345678
90123456
789012345
6789012345
When we learn programming, it is important to just gradually increase the difficulty of our problem, which is the goal of this series.