How can I write right-justified into a 12 chars width field?

Discussion in 'Java' started by Catherina Svensson, Apr 29, 2008.

  1. Lets say I have a String var which can contain values of different lengths e.g.
    "aaa" or "bb bb bb".

    I want to print them out with System.out.println right-justified with a field width
    of 12 chars. If necessary this field should be left padded with blanks.
    For the samples above the output should be e.g.:

    " aaa"
    and
    " bb bb bb"

    How can I implement this right-justified, blank padded, fixed-width filed output in Java?

    Cat
     
    Catherina Svensson, Apr 29, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. nobody
    Replies:
    5
    Views:
    610
    Jukka K. Korpela
    Dec 14, 2004
  2. Replies:
    5
    Views:
    1,117
    Ian Rastall
    Jun 29, 2005
  3. =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=

    Left justified or center justified under XSL:FO

    =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=, Feb 9, 2007, in forum: XML
    Replies:
    0
    Views:
    497
    =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=
    Feb 9, 2007
  4. Ben Thomas
    Replies:
    7
    Views:
    275
    Jan Svitok
    Nov 16, 2006
  5. Thomas Blabb
    Replies:
    3
    Views:
    279
    Paul Lalli
    Nov 16, 2007
Loading...

Share This Page