• Post Reply Bookmark Topic Watch Topic
  • New Topic

Question about building a pyramid  RSS feed

 
Tiberius Marius
Ranch Hand
Posts: 115
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey ,

Learning programming /java and i don't seem to understand something .

I m trying to make a pyramid from blocks . I know that for example to make a bigger block from small blocks you write something like :



but i cant seem go grasp how to make a pyramid , so far my best effort is :



At the moment visually i don't get a pyramid but it might be because of other issues and not because of the while and then a for inside it approach .

Can you tell me if my approach is correct and if now what would be the correct one to create a pyramid from smaller blocks ?
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tiberius Marius wrote:I know that for example to make a bigger block from small blocks you write something like :

Is there any reason that you didn't UseCodeTags (←click) this time Tiberius?

I notice that you have in your previous posts, and you can use the "Edit" button to correct your post.

Thanks

Winston
 
Tiberius Marius
Ranch Hand
Posts: 115
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmm

should work with two for statements as well right ?


but i practice it does not work need a short break
 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post the actual code here so we can help.
Maybe you are missing print new line statements? Are you even printing to the console? Or drawing on Swing component?
I don't want to guess ;).
 
Tiberius Marius
Ranch Hand
Posts: 115
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



At this point i m trying to create a triangle where the lowest level has 14 small blocks , the next (upper one) has 13 etc until the highest with just one block. At this point it's not important that it looks like a isoscel triangle and not a pyramid . Please do not give me the solution , i can google it myself , i m interested of how to make the rows shorted by one bock each time (that's why i added the println - to see how many loops/for are processed and how the values change.)

LE. I understand what i did wrong i think (j after the first loop will have the values 0 so it will not trigger the for any longer) , i think i can solve it simply by using the same variable in both for statements .Now it feels logical but i think i spend 1 h + thinking of a solution :|
 
Tiberius Marius
Ranch Hand
Posts: 115
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


now to deal with x coordonates so it s a pyramid and not a isoscel triangle
 
Tiberius Marius
Ranch Hand
Posts: 115
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
still nothing , does anyone have a solution here ?

the topmost block must be getWidth() /2 - BRICK_WIDTH /2 as the starting point . A block is created using x (left most point of the 4 points that define a block) and y (upper most point that defines a block) and then width length and height . Or the coordonates for the upper -left most point of the block using the width length and height.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!