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 4 of 4

Thread: Creating pyramids with for loops

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Creating pyramids with for loops

    Post deleted
    Last edited by jericajam; August 26th, 2011 at 07:07 PM.


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Creating pyramids with for loops

    Most important advice you can get: don't shove all your code into the main method. Break it down into smaller chunks and put each of these into their own methods.
    main method {
        while user has not finished {
            get user choice
            if user selects c {
                call method to print normal pyramid
            else if user selects d {
                call method to print upside down pyramid
            }
            // etc
        }
    }

  3. #3
    Member vanDarg's Avatar
    Join Date
    Jan 2011
    Location
    Chicago
    Posts
    65
    My Mood
    Mellow
    Thanks
    1
    Thanked 7 Times in 7 Posts

    Default Re: Creating pyramids with for loops

    I would set up the for loops as follows: Have one outside loop, with two other loops nested inside it, calculating spaces and size of the tree:

    for ( ; ; ){     // Represents what row is being worked on
        for ( ; ; ){   // Represents the column for spaces
         // Print space(s)
        }
        // Make sure you decrement amount of spaces here
        for ( ; ; ) {  // Represents the column for the asterisks
        // Print asterisk(s)
        }
       // Begin a new line
    }
    "Everything should be made as simple as possible, but not simpler."
    Asking Questions for Dummies | The Java Tutorials | Java Coding Styling Guide

  4. #4
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Creating pyramids with for loops

    Hello jericajam.

    Welcome to the forums.

    Please use the forum search function or check the "Similar Threads" box at the bottom of this thread.
    The 'pyramid for loop' question has been asked time and time again.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Similar Threads

  1. help with loops... :(
    By Macgrubber in forum Loops & Control Statements
    Replies: 2
    Last Post: November 2nd, 2010, 12:38 PM
  2. Help with Nested Loops
    By Plural in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 23rd, 2010, 03:31 PM
  3. Java Loops help please?
    By Sarah-Perkin in forum Loops & Control Statements
    Replies: 2
    Last Post: December 6th, 2009, 02:52 PM
  4. need help with loops plz
    By Kilowog in forum Loops & Control Statements
    Replies: 4
    Last Post: September 28th, 2009, 08:11 AM
  5. Replies: 11
    Last Post: April 29th, 2009, 03:12 AM