Results 1 to 3 of 3
Thread: formating output
- 10-12-2012, 08:19 PM #1
Member
- Join Date
- Jul 2012
- Posts
- 93
- Rep Power
- 0
formating output
OK, I have a program that has an output that looks like this:
What I need it to do is format with the last closing bracket of each line to be directly above the one below it; for example:Java Code:(105, 111) (120, 16) (149, 62) (26, 79) (10, 45) (53, 100) (98, 118) (44, 73) (70, 116) (92, 98) (9, 138) (137, 132) (116, 115) (2, 108) (35, 104)
here is what I have so far in a pringtf StringJava Code:(105, 111) (120, 16) (149, 62 ) ( 26, 79 ) ( 10, 45 ) ( 53, 100) ( 98, 118) ( 44, 73 ) ( 70, 116) ( 92, 98 ) ( 9, 138) (137, 132) (116, 115) ( 2, 108) ( 35, 104)
It is out.printf because I'm putting it in a file and I am also looping it 5 times which is why there are five different lines.Java Code:out.printf("(" + x1 + ", " + y1 + ") " + "(" + x2 + ", " + y2 + ") " + "(" + x3 + ", " + y3 + ")");Last edited by pbrockway2; 10-13-2012 at 12:33 AM. Reason: code tags added
- 10-12-2012, 08:39 PM #2
Member
- Join Date
- Jul 2012
- Posts
- 93
- Rep Power
- 0
Re: formating output
The answer
Java Code:out.printf("(%3d, %3d) (%3d, %3d) (%3d, %3d)", x1, y1, x2, y2, x3, y3 );
- 10-13-2012, 12:47 AM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
Re: formating output
I've added code tags to the example output - they're about the nearest thing we have to <pre> here I think, and are useful when formatting matters.
Ignoring the typo in the second line you seem to be right aligning the first number of the pair and left aligning the second. In code that would look like
Using - for alignment and %n for the newline is discussed in the API docs.Java Code:"(%3d, %-3d) (%3d, %-3d) (%3d, %-3d)%n"
(Or it may be that what you came up with is completely satisfactory - I'm mostly posting in case someone later finds the API docs useful.)
Similar Threads
-
Formating numbers makes wierd letter insead of comma.
By Dowie in forum New To JavaReplies: 9Last Post: 05-14-2012, 11:09 AM -
XSLT | disable-output-escaping adding a new line to the output
By smarty_m2002 in forum Advanced JavaReplies: 2Last Post: 05-03-2012, 11:39 AM -
how to get the resultset output into an output file
By renu in forum New To JavaReplies: 0Last Post: 09-30-2010, 08:16 PM -
Problem with formating comments
By Lubomirus in forum EclipseReplies: 0Last Post: 07-07-2009, 08:37 AM -
Java, output string, getting correct output? HELP!
By computerboyo in forum New To JavaReplies: 2Last Post: 02-25-2009, 11:44 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks