Results 1 to 3 of 3
Thread: Stars program
- 11-05-2012, 12:35 AM #1
Member
- Join Date
- Nov 2012
- Posts
- 1
- Rep Power
- 0
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++)
System.out.print("*");
System.out.println();
}
}
}
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.
- 11-05-2012, 05:55 AM #2
Member
- Join Date
- Mar 2011
- Posts
- 44
- Rep Power
- 0
Re: Stars program
Have you considered using spaces instead of stars, and using stars where you have used spaces for the bottom part?
- 11-09-2012, 05:17 PM #3
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
-
Java Stars Program
By DGray16 in forum New To JavaReplies: 1Last Post: 10-24-2012, 11:16 PM -
Java stars program
By andnlou2678 in forum New To JavaReplies: 3Last Post: 11-15-2011, 12:47 PM -
Two triangles of stars next to each other
By Aero in forum New To JavaReplies: 3Last Post: 09-26-2011, 07:20 PM -
stars
By nalinda in forum New To JavaReplies: 3Last Post: 08-25-2009, 11:48 AM -
Blinking stars
By jholtt23 in forum New To JavaReplies: 0Last Post: 02-19-2009, 05:38 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks