View Single Post
  #2 (permalink)  
Old 02-06-2008, 07:25 AM
CaptainMorgan's Avatar
CaptainMorgan CaptainMorgan is offline
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 839
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
You didn't really explain the specifics of the triangle, so this first example here is a left aligned triangle. I formatted it my way since you didn't properly format the post - please use code tags when posting code. There's many ways to do it... and I fancy for loops in case you didn't notice.


Replace your two while loops with either of the below snippets of code:
Code:
... for (i = 0; i < stars; i++) { for (j = 0; j <= i; j++) { System.out.print("*"); } System.out.println(); } ...
Since your square was hollow, here's a hollow triangle - also left aligned:
Code:
... for (i = 0; i <= stars; i++) { for (j = 0; j <= i; j++) { if (i == stars) { for (int x = 0; x<= stars; x++) System.out.print("*"); break; } else if (i > 1) { System.out.print("*"); for (int k = 0; k < i - 1; k++) System.out.print(" "); System.out.print("*"); break; } else System.out.print("*"); } System.out.println(); } ...
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums!
(closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
!
Got a little Capt'n in you? (drink responsibly)
Reply With Quote