• 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.

how to draw a triangle using java?

skim milk

Diamond Member
so the output should look something like this..

Please enter the height of the triangle: 3

*
**
***
**
*


the height can be inputted by the user to be any number
 
You start by whipping out a piece of paper, sketching and writing some pseudo code. Then you use out a text editor or something and start writing some code, compiling it, running it and refining it until you've gotten as close as you can on your own. Then, if you have a specific question about how something works in java, you come to a forum like this and ask for an explanation.
 
I believe kamper is referring to this.

OP, you need to design an algorithm to do this. You've got one input (or parameter), called 'height'. From that, you need to be able to program what each line would look like. I'd suggest starting by finding the relationship between that value and the total number of lines to print. Then figure out, for each line, given the overall height, how many asterisks to print. That's not the only way to approach the problem, but it's direct. Any more details, and it would be literally writing your solution for you.
 
Originally posted by: diegoalcatraz
OP, you need to design an algorithm to do this. You've got one input (or parameter), called 'height'. From that, you need to be able to program what each line would look like. I'd suggest starting by finding the relationship between that value and the total number of lines to print. Then figure out, for each line, given the overall height, how many asterisks to print. That's not the only way to approach the problem, but it's direct. Any more details, and it would be literally writing your solution for you.
This is what I would say as well, it's helpful but doesn't give you the solution. I guess it's like when you need to find an equation describing the pattern between numbers in a sequence: you write them out then look for relationships between them to come to a end result. Draw out what you need (do several cases, like height 1, height 2, height 5, make sure your algorithm works for any height), then figure how in a loop of some sort you would use your height parameter to draw the correct # of asterisks, go to new line and draw more, etc. kamper is correct too. Some of the guys here are awesome programmers.. they could answer just about any question you can think of (and even I can help with the lower level classes 🙂), but you need to try things on your own. Come up with possible solutions and what problem(s) are preventing you from completely getting it, then someone is usually more than willing to give you some help.
 
Originally posted by: Ned Flanders
Someone is on his daily period.
No, it's just that september always brings out the people who want their homework done for them.
 
Back
Top