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

Thread: Loops in a Pyramid problem

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Loops in a Pyramid problem

    Hello everyone,

    Eventhough this is my first post, I've been reading, and browsing this forum a lot. I have a problem figuring out how to draw a pyramid as follow (minus the *s)

    ********A
    ******A*B*A
    ****A*B*B*B*A
    **A*B*B*B*B*B*A
    A*B*B*B*B*B*B*B*A
    The problem is that it has A, B and a space between them.

    I was thinking of drawing two separate pyramid, as follow:

    ********A
    ******A***A
    ****A*******A
    **A***********A
    A***************A
    And another one:

    ********B
    ******B*B*B
    ****B*B*B*B*B
    **B*B*B*B*B*B*B

    However, I really appreciate all your input/help on this. I seem to have a hard time finding a good mathematic equation for the "for loops"

    Thanks for your time, everyone.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,607
    My Mood
    Hungover
    Thanks
    145
    Thanked 658 Times in 563 Posts

    Default Re: Loops in a Pyramid problem

    You aren't really going to be able to draw them separately.

    I'd start out by drawing a pyramid with a single character, then taking care of the special cases after you have that working.
    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
    Nov 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Loops in a Pyramid problem

    Quote Originally Posted by KevinWorkman View Post
    You aren't really going to be able to draw them separately.

    I'd start out by drawing a pyramid with a single character, then taking care of the special cases after you have that working.
    Thanks Kevin for your advice.

    I've got it worked out by uding drawString, given the first posistion of the letter, each time it's one less X position and one higher Y position.

    The for loop took care of the drawing.

    Thanks again.

Similar Threads

  1. problem in pyramid of number in java
    By akosiangelo12 in forum Loops & Control Statements
    Replies: 2
    Last Post: August 8th, 2012, 01:15 PM
  2. problem with my code (FOR LOOPS) neeed help plZ
    By jessy sonita in forum Loops & Control Statements
    Replies: 11
    Last Post: December 12th, 2011, 11:22 AM
  3. Need help on the pyramid number!
    By nicetan in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 14th, 2011, 04:43 PM
  4. Problem in the loops
    By shubhen in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: July 22nd, 2011, 03:45 AM
  5. [SOLVED] I am a java newb and I am having a problem with my while loops.
    By Deaththekid in forum Loops & Control Statements
    Replies: 22
    Last Post: July 10th, 2011, 08:26 AM