aspose file tools*
The moose likes Beginning Java and the fly likes Alignment of output Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Alignment of output" Watch "Alignment of output" New topic
Author

Alignment of output

John Valiant
Greenhorn

Joined: Mar 01, 2012
Posts: 26


1.I badly need to align the above output.I used the below printf.
2.Some how when i use %- in the second columns it doesnt work.
3.If you cant assist me in the code..pleases dont offer suggestions.



Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39846
    
  28
Don’t use \n. Use %n.
Your number columns are wider than the heading, but that is doubtless obvious to you too. Why have you got spaces between the successive format tags? They are probably unnecessary, but probably not the cause of your problem.
It worked perfectly when I tried it on a bash shell; are you using Windows®? Unless it has something to do with line ends, don’t know.
John Valiant
Greenhorn

Joined: Mar 01, 2012
Posts: 26
Campbell Ritchie wrote:Don’t use \n. Use %n.
Your number columns are wider than the heading, but that is doubtless obvious to you too. Why have you got spaces between the successive format tags? They are probably unnecessary, but probably not the cause of your problem.
It worked perfectly when I tried it on a bash shell; are you using Windows®? Unless it has something to do with line ends, don’t know.





the point is my 7,8,9,10 output move slightly to the right because of more numbers.I am using notepad++.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

John Xxx wrote:
Campbell Ritchie wrote:Don’t use \n. Use %n.
Your number columns are wider than the heading, but that is doubtless obvious to you too. Why have you got spaces between the successive format tags? They are probably unnecessary, but probably not the cause of your problem.
It worked perfectly when I tried it on a bash shell; are you using Windows®? Unless it has something to do with line ends, don’t know.





the point is my 7,8,9,10 output move slightly to the right because of more numbers.I am using notepad++.


And Campbell's point was that, since it works fine for him in a *n*x terminal, and since \n is the wrong choice for a line-end, that it may be some combination of your line-end and display application.

Did you try switching to %n as he suggested?

Also, I would add a suggestion to run it on the command line and see if that makes a difference.

(Also, you should thank Campbell for taking the time to test it even without you having provided an SSCCE.)
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

works for me, I was to lazy to look up the formula, so just did this and it worked, in eclipse.
So unitil you post us your actual code, not much more we can do.

John Valiant
Greenhorn

Joined: Mar 01, 2012
Posts: 26
ok here is my code.









Wendy Gibbons wrote:works for me, I was to lazy to look up the formula, so just did this and it worked, in eclipse.
So unitil you post us your actual code, not much more we can do.

Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

John Valiant wrote:ok here is my code.





Here's what I get:

Looks the same in both a cygwin txvt terminal and a cmd.exe console.

The only thing you need to fix in the code is that the first column doesn't account for multiple digits in miles. (Probably the third column for kM too, but since they're all 2 digits, you don't see it.)

I would change the first column to %2.0f to get the first miles column right-aligned, and I would run it in a command console if I were you.
John Valiant
Greenhorn

Joined: Mar 01, 2012
Posts: 26
Thanks guys for all the suggestions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39846
    
  28
You’re welcome Have you seen any improvement in the display?
John Valiant
Greenhorn

Joined: Mar 01, 2012
Posts: 26
Campbell Ritchie wrote:You’re welcome Have you seen any improvement in the display?


Hahaha..Actuall no..but thanks..i summited my assignment anyway.I figure if you guys had trouble figuring it..so will the rest of my novice mates
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Alignment of output