java programming help

itszlikewhoa

Junior Member
Mar 11, 2005
2
0
0
ok so i get how to do the first triangle and here's the code i came up with for it:
public void starsA()
{
final int MAX_ROWS = 6;

for(int row = 1; row <=MAX_ROWS; row++)
{
for(int star =1; star <=row; star++)
System.out.print ("*");
System.out.println();
}
}

however, I'm lost as to how to code the rest... (esp. the diamond) using loops. like I know that you also have incorporate some space delimiters in the code, but that's about it.

any help would be greatly appreciated :)

edit: didn't know there was an attach code button. sorry!
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
First hint: use the attach code function to post your stars, that'll save the formatting. For those who don't want to view the page source, B, C and D are all supposed to be right-aligned.

To get the right-aligned ones you will want to have two loops side by side. The first one prints out some spaces, then the second one some stars. Then you do it all over again for each line but with different numbers of stars and spaces. For D, first do a B and then a C, just with adjusted numbers.