> >>>> Alright I'm having a bit of trouble getting started for this
> >>>> assignment in my Java class.
[quoted text clipped - 16 lines]
>
> Patricia
In no way, was I trying to get anyone to give me the answer.. I really
want to learn to program well and was just stuck on this problem..
I've figured out how to make a left justified triangle by prompting
for input n and using a for loop where i < n to print out "[]" *(i+1).
Now, I'm just unsure how to do it where the triangle is centered and
right justified. Any advice? Thank you.
Lew - 18 Feb 2007 18:49 GMT
> In no way, was I trying to get anyone to give me the answer.. I really
> want to learn to program well and was just stuck on this problem..
> I've figured out how to make a left justified triangle by prompting
> for input n and using a for loop where i < n to print out "[]" *(i+1).
> Now, I'm just unsure how to do it where the triangle is centered and
> right justified. Any advice? Thank you.
As Patricia suggests frequently, step back from the computer and think about
the problem, what it actually means, and what steps you would have to follow
using paper and pen[cil] to step through the algorithm.
So you have to ask yourself,
- What is a "triangle"? You partially answered this in your first draft.
- What is "centered"? (Hint: "centered" implies a notion of total width.)
- What is "right justified"?
- In each case, what would the program output look like? Actually draw a picture.
- What out of a computer onto a screen, paper or other output medium would
make pictures at least approximately like that?
- What are the output commands that would produce such pictures?
- What data are needed by these commands in order to get it right?
- Lew
Alex Hunsley - 18 Feb 2007 19:41 GMT
>>>>>> Alright I'm having a bit of trouble getting started for this
>>>>>> assignment in my Java class.
[quoted text clipped - 17 lines]
> Now, I'm just unsure how to do it where the triangle is centered and
> right justified. Any advice? Thank you.
Ah, much better...
We have a much better idea of how to help people if they say exactly how
far they've got, and what problems they might now be having. Now we know
you're not just hoping for a readymade solution to be dropped on your
lap like some other people are!
So, doing a few sketches on paper of the various example would be a good
idea, as others have suggested, and Patricia's advice is good.
A hint: you might want to be outputting some space characters (' ')
before things in order to get visible characters like '[]' to appear
more to the right of the screen...
lex
James Bryan Chua - 18 Feb 2007 20:28 GMT
> >>>>>> Alright I'm having a bit of trouble getting started for this
> >>>>>> assignment in my Java class.
[quoted text clipped - 32 lines]
>
> lex
I think I've figured out how to do the right justified one, but I'm
still pretty stumped by the center justified one. I could do the same
for loop that I did with the other one but add a " " * n --
Lew - 18 Feb 2007 21:36 GMT
> I think I've figured out how to do the right justified one, but I'm
> still pretty stumped by the center justified one. I could do the same
> for loop that I did with the other one but add a " " * n --
How far into a line is its center?
- Lew
James Bryan Chua - 18 Feb 2007 21:51 GMT
> > I think I've figured out how to do the right justified one, but I'm
> > still pretty stumped by the center justified one. I could do the same
[quoted text clipped - 3 lines]
>
> - Lew
Depends on how many rows the user inputs..
Lew - 18 Feb 2007 22:08 GMT
>>> I think I've figured out how to do the right justified one, but I'm
>>> still pretty stumped by the center justified one. I could do the same
>>> for loop that I did with the other one but add a " " * n --
Lew wrote:
>> How far into a line is its center?
> Depends on how many rows the user inputs..
Isn't a row the same thing as a line?
My question has to do with each separate line of output. For example, let us
say you had a line like this (not part of a triangle):
^blah.didi.rightHere!!thereItIs.blaa.ahha.$
where '^' represents the beginning of the line and is not meant to represent a
literal character, and likewise '$' represents the end of line, not a literal
character.
Where is the center of that line?
What if it had spaces in it instead of some of the other characters?
What if it had spaces in it in lieu of any other character?
- Lew
Mark Space - 20 Feb 2007 22:21 GMT
>>> I think I've figured out how to do the right justified one, but I'm
>>> still pretty stumped by the center justified one. I could do the same
[quoted text clipped - 4 lines]
>
> Depends on how many rows the user inputs..
Hint: Ignoring "characters" for now, how would you normally find the
midpoint of a line? Isn't the midpoint the same as it's "center?"
>>>>> Alright I'm having a bit of trouble getting started for this
>>>>> assignment in my Java class.
[quoted text clipped - 17 lines]
>
> Patricia
Which is exactly what *I* was trying to do. And since there's no way I
could possibly code a solution to the problem without asking for /
looking for help, I tried to supply a starting point.