Results 1 to 5 of 5
Thread: triangle
- 11-07-2010, 05:16 PM #1
Member
- Join Date
- Oct 2010
- Posts
- 56
- Rep Power
- 0
triangle
Hi guys, i'm trying to print a triangle (which is taken from a command line argument) so that its longest row is at the top and the right hand side straight.
I'm guessing another loop is required:
Any suggestions?Java Code:public class PrintTriangleMirror { public static void main(String [] args) { int height = Integer.parseInt(args[0]); for (int row = 1; row <= height; row++) { for (int column = 1; column <= row; column++) System.out.print("[_]"); System.out.println(); } } }
Kind regards
ShyamLast edited by Shyamz1; 11-07-2010 at 05:46 PM.
- 11-07-2010, 05:43 PM #2
Member
- Join Date
- Oct 2010
- Posts
- 56
- Rep Power
- 0
So do you have any suggestions on how to flip the triangle. I know another for loop is required... and you can think about the spaces.
So you can use a for loop... but i dont what to include in it.
kind regards
Shyam
-
You marked the wrong thread as solved and haven't used code tags yet.... :)
- 11-07-2010, 05:49 PM #4
Member
- Join Date
- Oct 2010
- Posts
- 56
- Rep Power
- 0
Yeah i know sorry, and i have edited the code and use code tags if you may look :). i used code and /code
Last edited by Shyamz1; 11-07-2010 at 05:53 PM.
-
How about having two inner for loops in a row, one to print spaces, the other to print your lines:
Java Code:outer loop -- loop through the rows inner loop 1 print spaces end inner loop 1 inner loop 2 print "_" end inner loop 2 println end outer loop
Similar Threads
-
Triangle using Numbers
By Anandt88 in forum New To JavaReplies: 16Last Post: 06-05-2010, 04:10 PM -
ASCII Triangle
By physics in forum New To JavaReplies: 2Last Post: 03-13-2010, 01:00 AM -
triangle program
By computerbum in forum New To JavaReplies: 8Last Post: 03-02-2010, 04:55 AM -
Triangle
By jkswebsite in forum New To JavaReplies: 8Last Post: 01-10-2009, 02:08 PM -
Is it a right triangle? (Code help)
By TheApostle in forum New To JavaReplies: 8Last Post: 10-07-2008, 08:39 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks