Overview
This exercise is slightly more complicated than the previous one. You will be required to put one for loop inside another, a technique known as nesting.
Your task is create a triangle as shown below.
: java LopsidedNumberTriangle 1 22 333 4444 55555 666666 7777777 88888888 999999999 :
To do this, you should use two loops:
- The first will contain a loop variable line_num which will take values from 1 to 9, i.e. corresponding to each line of the triangle.
- Inside the first loop you should place a nested loop. This loop will have a different loop variable, char_num, whose values will run from 1 to line_num. From within the inner loop, we print out the value of line_num. After the nested loop has completed, you will need to start a new line.
Create a LopsidedNumberTriangle that prints out the triangle above.
An automated test has been created for this exercise: LopsidedNumberTriangleTest.java.