Results 1 to 2 of 2
Thread: Outputting a * triangle
- 10-16-2010, 08:45 PM #1
Member
- Join Date
- Oct 2010
- Posts
- 1
- Rep Power
- 0
Outputting a * triangle
Hey I am new to forums, so if I don't put something in the post please tell me. I am trying to out put a "*" triangle from a user input of the height and base, but not just a regular right triangle. If the user put in a height of 3 and a base of 5 it should look like this
*
***
*****
i just cant figure out the algorithm to use in a for loop. This is what I have for the for loop so far
for(int i=0; i < triHeight;i++)
{
for(int j = 1; j<=triBase; j++)
{
System.out.printf("*");
}
System.out.println();
}
with triHeight and triBase being ints entered by the user. This prints out a square. I was told that the j increment should have something to do with the base and the height but i am really lost.
- 10-17-2010, 11:39 AM #2
Senior Member
- Join Date
- Oct 2010
- Posts
- 317
- Rep Power
- 3
blackbeltsas,
Firstly, welcome to the forums.
The problem you are having relates to the second for loop. As the value of 'triBase' never changes between loops, the output for each repetition is always going to be the same.
I'm not going to give you the code straight off, that would be too easy. Instead I can point you in the right direction.
As already mentioned, the value in the second for loop needs to change between repetitions. But what value should this take?
Just to get you started, divide 'triBase' by 'triHeight' this give you the increment per line.
If you're still stuck then post back.
Regards.
Similar Threads
-
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 -
Simple Addition Program Outputting Wrong Value
By carlodelmundo in forum New To JavaReplies: 4Last Post: 08-05-2008, 03:37 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks