You want
1
22
333
4444
55555
Step by Step:
1) Write the class and main method headers and compile.
2) Create a loop that prints 5 lines of numbers. Print the numbers 1 - 5 on each line. Just print 1 number on each line using System.out.print. Then print one line return using System.out.println. Compile and run.
3) Each number needs to print as many times as the line you are on. So when you are on line 1, print 1 number. On line 5, print 5 numbers. To do this, surround your print statement with a for loop to print as many times as the line you are on. This is a loop inside the loop that prints 5 numbers. Compile and run.
4) Now, move the triangle over by inserting spaces on each line. Add a loop of spaces to print before the first line. Just try to move the entire triangle over 5 spaces each time. Create a loop that is inside the line loop but before the number loop. It should end before the number loop begins. Just loop to print 5 spaces. Compile and run and see the numbers all moved over 5 spaces.
5) Change the spaces to print 4 the first time, then 3, 2, 1, 0. In the loop
for the numbers, you could just use the counter of the line loop as your stopper.
For the spaces, you will need to determine how you can adjust the line counter
to be 4 the first time and then 3, 2, 1, 0. (5 minus line might work.) Compile
and run and see the final result.
Pseudocode for final version:
public class Triangle
{
public static void main()
{
for (int manNumber = 1,
manNumber < 6, manNumber++) // loop of man printing
{
//
loop of spaces
//
loop of numbers
//
go to a new line
}
}
}