Well, the more important question is do YOU have any ideas? Many folks who hang out here could write something to do this pretty quick, but that wouldn't help you learn anything. And that's what this site is about - helping you learn.
So, where are you in the process? Have you downloaded and installed the JRE? Do you know how to write and compile anything? Have you made an attempt at this problem, and if so, what worked or didn't work?
are you supposed to print it out EXACTLY like this, dashes and all, or did you just use those dashes to show us the spacing?
please post any code you have, and tell us exactly where you are stuck - does it compile? does it run at all? does it get stuck in a loop somewhere?
note that when you do post code, please use the "code" tags. you can click the button down below to get them, the just paste your code between the two tags - this will preserve your indentation, which makes the code MUCH easier for us to read.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Perhaps it may help to consider a simpler problem, then modify the solution. Could you write something to print this?
Or if that's too complex, how about this?
"I'm not back." - Bill Harding, Twister
Joined: Nov 27, 2006
ok thanks. well so far I have this
but I'm not sure how to do the dashes :/
Joined: Jan 30, 2000
All right, good. Now how about something like this:
Here I have replaced 1 dash with the number 1, 2 dashes with the number 2, etc. The idea is to hopefully find a mathematical relationship between the numbers on each line, without (yet) worrying about how to print, say, 3 dashes.
Again, if that seems like overload, you can first try a simpler version of the problem, ignoring the last column:
That +=2 was pretty good! We see the i++ so often it's easy to miss using other numbers to increment. The condition <10 might be confusing. Would you find it more like natural English to say <=8 ?
Now try the leading dashes. You can increment by 1 this time and build a string of dashes with String concatenation ...
dashes += "-";
In that loop i will equal 1,2,3,4. How could you quickly get 2,4,6,8 out of that?
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Joined: Jan 30, 2000
OK, Stan and I posted at about the same time, but chose different directions to go in. Really though, you can pick either one - whichever you have a better idea about. In either case, you want to modify your solution to something which is somehow closer to the final form. The order that you make these changes in is up to you.