Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: Trying to create pyramid using a for loop

  1. #1
    Junior Member
    Join Date
    Jan 2014
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Trying to create pyramid using a for loop

    pyramid.jpg


    Can someone help me write a for loop for creating a pyramid starting on the platform with the bottom line consisting of 10 boxes then 8 then 6 and so on. I have attempted making the first row but when i run the program the boxes all split up and fall over.

    Any help would be appreciated.

    Thank you.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Trying to create pyramid using a for loop

    What have you tried? Where are you stuck? Where is your SSCCE?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Jan 2014
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Trying to create pyramid using a for loop

    The 2nd for loop is me trying to make a base of the pyramid, what do i need to do build more boxes on top of the base and then on top of that?

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Trying to create pyramid using a for loop

    I don't see any code, and asking us to debug a grainy screenshot is pretty lazy. Copy and paste your code here, in a way that we can compile and run it, and we'll go from there.

    However, it's hard to answer general "how do I do this" type questions other than to point you to google. What have you tried to build more bases on top of your first one?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Junior Member
    Join Date
    Jan 2014
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Trying to create pyramid using a for loop


  6. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Trying to create pyramid using a for loop

    Asking us to debug a grainy screenshot is pretty lazy. Copy and paste your code here, in a way that we can compile and run it, and we'll go from there.

    Also, this seems to be a question for a specific framework (Box2D?), so you might want to ask your instructor about this.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    Junior Member
    Join Date
    Jan 2014
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Trying to create pyramid using a for loop

    yeh it is, sorry.

    im not going to be in uni for a few days so i thought id get help here, but it doesnt matter.

    Thank you

  8. #8
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Trying to create pyramid using a for loop

    You can try to post your code here, but Box2D is actually a C++ (or maybe C?) library that is wrapped by Java. I would maybe guess that you're accidentally spawning your boxes on top of each other, which causes them to bounce off of each other.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  9. #9
    Junior Member
    Join Date
    Jan 2014
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Trying to create pyramid using a for loop

    thank you for your help, i will email my teacher, you can close this thread if you want. your help was appreciated.

Similar Threads

  1. [SOLVED] For loop to create string.
    By clyxee in forum Loops & Control Statements
    Replies: 21
    Last Post: December 12th, 2013, 09:40 AM
  2. Create JRadioButtons from HashMap by loop
    By poundnmonitor in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 30th, 2013, 09:00 AM
  3. loop help need to create the letter L AND Y
    By YG N JYP FAM4EVA in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 26th, 2013, 01:56 PM
  4. I need to create a certain SHAPE with FOR LOOP.
    By Rage1337 in forum What's Wrong With My Code?
    Replies: 8
    Last Post: August 4th, 2012, 09:15 AM
  5. help with a loop (pyramid of numbers)
    By ande6870 in forum Loops & Control Statements
    Replies: 2
    Last Post: October 7th, 2010, 08:17 PM