It's good you're not asking people to do your homework.
That said, it may be more helpful to you, learning-wise, to be given a
general description of what you're looking for, and let you work the
details out on your own. So...
In the output you're looking at, note that there are two things that are
changing: the digit being displayed, and the length of the string being
displayed.
Note also that you even recall there were two loops. So, perhaps one loop
changes the digit, while the other loop controls the length of the string.
Finally, note that the length appears to be related directly to the
digit. In other words, the loop controlling the length of the string may
(i.e. will
) use the digit controlled by the one loop as its own
input. In this way, the loop controlling the digit also winds up
indirectly controlling the length of the string.
Here's a simple loop that changes the value of an integer from 1 to 9:
for (int i = 1; i <= 9; i++) { /* do something */ }
Here's a simple loop that writes a fixed number of strings ("1" to "10")
to the standard output:
for (int j = 1; j <= 10; j++) { System.out.printf("%d", j); }
Finally, note that while I have used constants in the loop expressions,
anywhere there's a hard-coded literal integer, you could instead put an
integer variable.
All of the above are the building blocks you need to answer your
question. You should now try on your own to assemble them in a useful way.
Finally, while it's not quite as bad to post questions like this one as
compared to asking for help with your homework, I would say that a
newsgroup not specifically intended for learning how to program is
probably not the best place for advice related to basic programming
techniques. Ideally, this is something better handled by contacting your
teacher and/or classmates for help, but if not, I suspect there are forums
out there that are specifically intended for helping people new to
programming.
I can't speak for the others reading this newsgroup, but while I don't
object to the occasional "I don't know how to program, please help"
question, it's not really something that should come up a lot in a
newsgroup like this one. That sort of thing can really reduce the
signal-to-noise ratio for the newsgroup if it gets to be commonplace.
Pete- Hide quoted text -
- Show quoted text -