File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Multiply PrintWriter output by user input Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Multiply PrintWriter output by user input" Watch "Multiply PrintWriter output by user input" New topic
Author

Multiply PrintWriter output by user input

James Brownie
Greenhorn

Joined: Jan 30, 2013
Posts: 3
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

Joined: Aug 07, 2007
Posts: 2415
    
  50
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

Joined: Jan 30, 2013
Posts: 3
Thanks Tony,

That did the trick!
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2415
    
  50
You're welcome
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11499
    
  16

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Multiply PrintWriter output by user input