Through trial and error, I have been able to get my pyramid close but not quite where it needs to be. I started with the hashes because it was difficult to interpret spaces in the output terminal and I am trying to understand the relationship of each initializing parameter in the for statement (my terminology is probably way off, so any input on that may help tremendously).


My pyramid is finally in the correct orientation and is in ascending order, but starts with a blank line (started with int b = r; b < n; b++ and the result was a pyramid upside down in descending order).

I feel like I am missing some sort of key concept when I am manipulating this second for statement. Looking for any guidance before I start trying to print the spaces.

  • In the future, please don't use screen shots to post code. It actually makes it harder to work with and impossible to cut and paste for testing. Just cut and paste from your IDE and format as needed. There are instructions on how to do so at I would also recommend that you review the following two posts: meta.stackexchange.com/questions/22186/… Everyone's forgiven the first time! ;-D
    – Cliff B
    Commented Nov 11, 2018 at 5:05
  • Sorry wont happen again. Commented Nov 12, 2018 at 10:17

1 Answer 1


Hmmm, it's funny, but most people have no trouble printing the #'s and fight with printing the spaces. You've almost figured out the spaces, but are having trouble printing out the hashes. Save your current and older code, you'll find it useful later. ;-)

On to the current problem. Think about what you're trying to do. How many #'s are printed on the first line of the pyramid? On the second? Third?

Does the number of hashes needed on a given line actually depend on the height of the pyramid? In other words, does a pyramid of height 4 have the same number of hashes on line 2 as a pyramid of height 16?

So, why is the inner for loop so complicated?

That should get you going! ;-)

Now, when you go to do spaces, forget this and think about how you created the upside down pyramid. ;-)

You'll find it useful to print something like "1" instead of spaces until you get it right. 1 is a lot easier to see and count. ;-)

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

  • thank you for your assistance. Since you stated that is was close to figuring out the spaces, I just changed to code to reflect that. After some trial and error I was able to get the spaces correct semi correct. However, I do have a new related question that maybe you can help me understand. Unfortunately it does not allow me to copy and paste code into comments, so I had to start a new question. Commented Nov 12, 2018 at 11:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .