This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multiply PrintWriter output by user input

 
James Brownie
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello ppl.

I have an issue in that I need to multiply the PrintWriter output by the user input.

One way I know of doing it would make multiple switch statements to cover every case then simply duplicate the outputStream line to match each case.

But this seems like a very long winded way around.

Is there an easier / better method of multiplying the output by the user input?

 
Tony Docherty
Bartender
Posts: 2965
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an issue in that I need to multiply the PrintWriter output by the user input.

One way I know of doing it would make multiple switch statements to cover every case then simply duplicate the outputStream line to match each case.

I'm not really sure what you mean by this but if it is that you want to output the counter value 'accross' times for each rollNumber then wrap the line of code for the output in an inner for loop which runs from 0 to < accross and take the newline char out of the output format string. Then output a newline char once the inner for loop has completed.
 
James Brownie
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tony,

That did the trick!
 
Tony Docherty
Bartender
Posts: 2965
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
fred rosenberger
lowercase baba
Bartender
Posts: 12147
31
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One of the greatest skills all developers need to learn is how to break down problems into their component parts. In this case, the problem was something like:

Print the output the number of times the user input

That can easily be broken into a few things:

Print something
do something a certain number of times
get a number from a user

Note that each of these can be done without regard to any of the other two. Sure, eventually you will have to pass the number you get from the user to the piece that does something some number of times...but that's pretty easy.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic