help - right allignment of text

Discussion in 'Java' started by EB, Feb 12, 2004.

  1. EB

    EB Guest

    Im working with Java.
    Im writing this program right now.....and one of the thing i have to do is
    present a matrix onto the screen....my problem is that i dont know how to
    make to make the far right colum of the matrix to be right aligned.
    Any help will be much appreciated

    heres what i have right now
    0.000 0.000 0.000 2.000
    0.000 0.000 0.000 12.000
    0.000 0.000 0.000 0.000
    0.000 0.000 0.000 138.000

    HERES WHAT I WANT
    0.000 0.000 0.000 2.000
    0.000 0.000 0.000 12.000
    0.000 0.000 0.000 0.000
    0.000 0.000 0.000 138.000

    Please help
     
    EB, Feb 12, 2004
    #1
    1. Advertising

  2. EB

    Huan Ding Guest

    System.out.println("%6.3f%6.3f%6.3f%6.3f", v1, v2, v3, v4);

    "EB" <> wrote in message
    news:...
    > Im working with Java.
    > Im writing this program right now.....and one of the thing i have to do is
    > present a matrix onto the screen....my problem is that i dont know how to
    > make to make the far right colum of the matrix to be right aligned.
    > Any help will be much appreciated
    >
    > heres what i have right now
    > 0.000 0.000 0.000 2.000
    > 0.000 0.000 0.000 12.000
    > 0.000 0.000 0.000 0.000
    > 0.000 0.000 0.000 138.000
    >
    > HERES WHAT I WANT
    > 0.000 0.000 0.000 2.000
    > 0.000 0.000 0.000 12.000
    > 0.000 0.000 0.000 0.000
    > 0.000 0.000 0.000 138.000
    >
    > Please help
    >
    >
     
    Huan Ding, Feb 12, 2004
    #2
    1. Advertising

  3. EB

    Carl Howells Guest

    Huan Ding wrote:
    > System.out.println("%6.3f%6.3f%6.3f%6.3f", v1, v2, v3, v4);
    >


    You *might* want to point out this won't work unless you have jdk 1.5,
    which is currently in beta. That would be helpful.
     
    Carl Howells, Feb 12, 2004
    #3
  4. EB

    Huan Ding Guest

    really? So i guess i'll stick with my c++ then.

    Huan

    "Carl Howells" <> wrote in message
    news:...
    > Huan Ding wrote:
    > > System.out.println("%6.3f%6.3f%6.3f%6.3f", v1, v2, v3, v4);
    > >

    >
    > You *might* want to point out this won't work unless you have jdk 1.5,
    > which is currently in beta. That would be helpful.
     
    Huan Ding, Feb 12, 2004
    #4
  5. EB wrote:
    > Im working with Java.
    > Im writing this program right now.....and one of the thing i have to do is
    > present a matrix onto the screen....my problem is that i dont know how to
    > make to make the far right colum of the matrix to be right aligned.
    > Any help will be much appreciated


    See the java.text package. And consider posting your beginner's
    questions to comp.lang.java.help

    /Thomas
     
    Thomas Weidenfeller, Feb 12, 2004
    #5
  6. EB

    Dale King Guest

    "Thomas Weidenfeller" <> wrote in message
    news:c0foo3$sd5$...
    > EB wrote:
    > > Im working with Java.
    > > Im writing this program right now.....and one of the thing i have to do

    is
    > > present a matrix onto the screen....my problem is that i dont know how

    to
    > > make to make the far right colum of the matrix to be right aligned.
    > > Any help will be much appreciated

    >
    > See the java.text package. And consider posting your beginner's
    > questions to comp.lang.java.help



    Actually nothing in java.text will help with this question. This requires
    padding with spaces and nothing in java.text does this. There is no API in
    Java that does this, primarily because it is almost always used in a
    non-portable way. Aligning with spaces assumes that the viewer of that
    output will be using a fixed width font, which is a non-portable assumption.
    There is no guarantee that even at command prompt that a fixed width font
    is being used. Not to mention that assuming that there even is a command
    prompt is non-portable.

    However Sun, did bow to the pressure in JDK1.5 and have added printf style
    formatting.
    --
    Dale King
     
    Dale King, Feb 13, 2004
    #6
  7. EB

    nos Guest

    "Dale King" <kingd[at]tmicha[dot]net> wrote in message
    news:...
    > "Thomas Weidenfeller" <> wrote in message
    > news:c0foo3$sd5$...
    > > EB wrote:
    > > > Im working with Java.
    > > > Im writing this program right now.....and one of the thing i have to

    do
    > is
    > > > present a matrix onto the screen....my problem is that i dont know how

    > to
    > > > make to make the far right colum of the matrix to be right aligned.
    > > > Any help will be much appreciated

    > >
    > > See the java.text package. And consider posting your beginner's
    > > questions to comp.lang.java.help

    >
    >
    > Actually nothing in java.text will help with this question. This requires
    > padding with spaces and nothing in java.text does this. There is no API in
    > Java that does this, primarily because it is almost always used in a
    > non-portable way. Aligning with spaces assumes that the viewer of that
    > output will be using a fixed width font, which is a non-portable

    assumption.
    > There is no guarantee that even at command prompt that a fixed width font
    > is being used. Not to mention that assuming that there even is a command
    > prompt is non-portable.
    >
    > However Sun, did bow to the pressure in JDK1.5 and have added printf style
    > formatting.


    But will it be like 'c' and not consider character width?

    > --
    > Dale King
    >
    >
     
    nos, Feb 14, 2004
    #7
  8. EB

    Dale King Guest

    "nos" <> wrote in message
    news:nHkXb.33492$_44.30031@attbi_s52...
    >
    > "Dale King" <kingd[at]tmicha[dot]net> wrote in message
    > news:...
    > >
    > > However Sun, did bow to the pressure in JDK1.5 and have added printf

    style
    > > formatting.

    >
    > But will it be like 'c' and not consider character width?



    Yes, it is a more powerful version of printf. It is inspired by C printf,
    but not 100% compatible. Read about it yourself:

    http://java.sun.com/j2se/1.5.0/docs/api/java/util/Formatter.html

    --
    Dale King
     
    Dale King, Feb 16, 2004
    #8
    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. Tom
    Replies:
    0
    Views:
    435
  2. Aitham alama

    Center allignment

    Aitham alama, Jul 18, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    349
    John Saunders
    Jul 18, 2004
  3. James

    allignment

    James, Mar 24, 2006, in forum: HTML
    Replies:
    5
    Views:
    533
    dorayme
    Mar 25, 2006
  4. Anthony

    allignment of structure

    Anthony, Nov 11, 2003, in forum: C++
    Replies:
    1
    Views:
    535
    Victor Bazarov
    Nov 11, 2003
  5. MisterE

    Memory allignment/type casting question

    MisterE, Oct 8, 2008, in forum: C Programming
    Replies:
    6
    Views:
    399
    CBFalconer
    Oct 9, 2008
Loading...

Share This Page