Results 1 to 2 of 2
Thread: For Loop
- 08-07-2008, 10:54 AM #1
Member
- Join Date
- Aug 2008
- Posts
- 15
- Rep Power
- 0
For Loop
Hi...
Anyone know how to display a triangle in the
1) Center and pointing up position
2) Center and pointing down position
for(int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
if(j >=i)
{
System.out.print("*");
}
else
{
System.out.print(" ");
}
}
System.out.println();
}
I have tried for hours but have no idea how to do.
- 08-07-2008, 02:01 PM #2
Take a piece of grid paper and draw in the figure you want.
Then for each row of the figure, do a println of a string with the *s spaced as per the drawing. For example for the point up, the first line would be a single centered *. As you move down there would be 2 *s with increasing spaces between then and decreasing spaces before and after them. The bottom line would be a row of *s all the way across.
Similar Threads
-
while loop
By Unknown1369 in forum New To JavaReplies: 5Last Post: 07-08-2008, 10:15 AM -
How to use Do While loop
By Java Tip in forum java.langReplies: 0Last Post: 04-17-2008, 07:45 PM -
How to use While loop
By Java Tip in forum java.langReplies: 0Last Post: 04-17-2008, 07:44 PM -
do...while loop
By eva in forum New To JavaReplies: 16Last Post: 01-31-2008, 06:44 AM -
while loop
By michcio in forum New To JavaReplies: 5Last Post: 01-27-2008, 12:56 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks