Results 1 to 3 of 3

Thread: Stars program

  1. #1
    adip is offline Member
    Join Date
    Nov 2012
    Rep Power

    Default Stars program

    I am taking computer science at school and our home work this weekend was to finish a program we have been working on the past week which was to program something that would print "*" in different patterns I am trying to finish the last one and have not been able to figure out an equation that will work. I need to print a diamond. so far I have gotten the top part to print by doing the following

    public class stars
    public static void main (String[]args)
    final int MAX_ROWS=10;

    for (int row=1; row<=(MAX_ROWS-5); row++)
    for (int star=1; star<=((MAX_ROWS-5)-row); star++)
    System.out.print(' ');
    for (int star=1; star<=((row*2)-1); star++)


    I have tried invertinf the equation and changing the number star is equal to along with row and if I am adding or subtracting a star. Any advice on how to get the bottom to print would be apprieciated.

  2. #2
    sibernewf is offline Member
    Join Date
    Mar 2011
    Rep Power

    Default Re: Stars program

    Have you considered using spaces instead of stars, and using stars where you have used spaces for the bottom part?

  3. #3
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Rep Power

    Default Re: Stars program

    So isn't a diamond just a centered collection of rows that contain first a growing number of * and then a diminishing number of stars?

    So, we can assume several things from this. We're doing something over and over, so: Loops
    You got that far.

    Also, we're doing two things over and over, rows, and columns. This implies a nested loop (a loop in a loop).

    Finally, we have two behaviors - a growing number of stars, followed by a shrinking number of stars. One way to do this is two sets of two loops, one that grows, and one that shrinks.

Similar Threads

  1. Java Stars Program
    By DGray16 in forum New To Java
    Replies: 1
    Last Post: 10-24-2012, 11:16 PM
  2. Java stars program
    By andnlou2678 in forum New To Java
    Replies: 3
    Last Post: 11-15-2011, 12:47 PM
  3. Two triangles of stars next to each other
    By Aero in forum New To Java
    Replies: 3
    Last Post: 09-26-2011, 07:20 PM
  4. stars
    By nalinda in forum New To Java
    Replies: 3
    Last Post: 08-25-2009, 11:48 AM
  5. Blinking stars
    By jholtt23 in forum New To Java
    Replies: 0
    Last Post: 02-19-2009, 05:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts