• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Alignment of output

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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.



 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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++.
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.)
 
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guys for all the suggestions:)
 
Campbell Ritchie
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You’re welcome Have you seen any improvement in the display?
 
John Valiant
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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:)
reply
    Bookmark Topic Watch Topic
  • New Topic