• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

java programming help

itszlikewhoa

Junior Member
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!
 
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.
 
Back
Top