Hi - I'm having a hard time figured out how to print the triangle shape below using loops. I did the two previous triangles with no issue but have no idea how to get the spaces in there. I'm really confused and would appreciate any help.

*
        **
       ***
      ****
     *****
    ******
   *******
  ********
 *********
**********
public static void main (String[]args)
	{
		final int MAX_ROWS = 10;
		
		for (int row = 10; row <= MAX_ROWS; row--)
		
		{		
			for (int star = 1; star <=MAX_ROWS; star++)
				System.out.print ("*");
				{
				for (int space = 1; space<=MAX_ROWS; space++)
					System.out.print(" ");
				}
			System.out.println();
					
		}
	}
}

You are on the right track. However, why do you need to print white space afterward? You just need to go to the next line after you finish printing out the * for each row... You need to start the row from 1, not right at Max. Also, you should use the maximum number of start to the row value you are at, not the Max value.

The triangle that shows when I post is not the correct one. Imagine that triangle upside down so that there are 9 spaces in the first row and then an asterisk and ends up with 10 asterisks in the tenth row.

Please redraw the triangle and use the "code" tag around the triangle, so we can see it exactly it should be.

Now the post is correct.

I figured it out:

{
	public static void main (String[]args)
	{		
		for (int row = 1; row <=10; row++)
		
		{		
			for (int space = 1; space<=10-row; space++)
				System.out.print(" ");
			
			for (int star = 1; star <=row; star++)
				System.out.print ("*");
				
			
			System.out.println();
					
		}
	}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.