Win a copy of Get Programming with Java (MEAP only) this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

the dreaded CS106a pyramid. Solved but needs improvement  RSS feed

Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I've solved the dreaded pyramid problem from the itunes Stanford CS106 course, and created myself a pyramid (hint to those having trouble, try manually coding your first two lines in order to figure out what exactly you want your for loops to do. I could have saved myself about a week of mental anguish if I did that!).

Two issues:

1) The pyramid is not quite centered and I'm having trouble figuring out how to do this: is there a set formula to use and memorize from here on out, or do I need to rework my algorithm?

2) How would you fix this code? If I were an actual CS106 student I'd have a prof and some TAs to help me out...but now I don't so I need your experience . Right now, I have each individual layer being laid from left to right, then measuring to go up by one layer, shift the row by 1/2 a brick length, and lay down one less brick per layer until we have one brick. Is there a better way to go about this that I didn't think of?

Thank you very much!

Posts: 4584
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Show us what your actual output looks like. Then show us what your desired output would look like.
Any sufficiently advanced technology will be used as a cat toy. And this tiny ad contains a very small cat:
Programmatically Create PDF Using Free Spire.PDF with Java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!