• Post Reply Bookmark Topic Watch Topic
  • New Topic

formatting strings  RSS feed

 
Ranch Hand
Posts: 68
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

How can i left justify a column of several rows of names, then right justify them?
 
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Can you explain in more detail, perhaps with an example, exactly what you want to do?
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome again

I suggest you start with this part of the Java Tutorials.
 
Carolin Sha
Ranch Hand
Posts: 68
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks anyway guys, i eventually figured it out.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And how did you sort it out?
 
Carolin Sha
Ranch Hand
Posts: 68
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

this is my code

 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the post; I have added code tags, since you are new (always use them) and removed a few blank lines, and doesn't it look a lot better

You have obviously read what I suggested. Don't use println(""); Either write println() or put a %n tags after printf.
 
Carolin Sha
Ranch Hand
Posts: 68
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome and well done getting it to work
 
Ranch Hand
Posts: 221
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote: Don't use println(""); Either write println() or put a %n tags after printf.

Campbell, would mind sharing some insight as to why?

Regards,
Robert
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because println is overloaded to take no arguments. That is specially intended for going to a new line.
Because using %n twice will only require one call to printf. Remember each of those print calls takes a long time, maybe a millisecond, which is millions of times slower than other operations.
 
Robert D. Smith
Ranch Hand
Posts: 221
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cleared that up nicely. Thanks.

Regards,
Robert
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!