Results 1 to 4 of 4
  1. #1
    msphelix is offline Member
    Join Date
    Aug 2012
    Posts
    9
    Rep Power
    0

    Default Using Format Specifiers as Text in printf()

    Hi,

    I want a System.out.printf() to display " ... a long must be formatted with %d, not %f:\n" +
    "myLong == %d works;\n", myLong);
    and have it ignore the %d and %f on the first line.

    How can I do this or do I need to put the first line in a println() instead of a printf()?

    System.out.println(" ... a long must be formatted with %d, not %f::\n" +
    "myLong == %f throws an Exception.");

    Thanks

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,762
    Blog Entries
    7
    Rep Power
    21

    Default Re: Using Format Specifiers as Text in printf()

    I closed your other (duplicate) thread; please start only one thread per problem. Maybe it helps to know that a double percent sign (%%) produces a single percent sign on the output.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    msphelix is offline Member
    Join Date
    Aug 2012
    Posts
    9
    Rep Power
    0

    Default Re: Using Format Specifiers as Text in printf()

    Thanks for the reply Jos.
    2 Things.
    1. The other thread I accidentally submitted without a title: I didn't know how to remove the post or edit it to fix the title so I submitted it again. Tell me how and I won't do it again.

    2. Thanks for the help; %%f does what I want it To :D

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,762
    Blog Entries
    7
    Rep Power
    21

    Default Re: Using Format Specifiers as Text in printf()

    I don't know if you can remove your own thread yourself (I'll do it for you); I'l glad that %% trick gave you the solution.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. printf VS printWriter.printf
    By Mapisto in forum New To Java
    Replies: 14
    Last Post: 01-20-2012, 01:29 PM
  2. Using printf without specifiers
    By FAkamo in forum New To Java
    Replies: 1
    Last Post: 10-17-2011, 09:46 AM
  3. system.out.printf versus system.out.format
    By bigsonny in forum New To Java
    Replies: 10
    Last Post: 06-21-2011, 11:40 PM
  4. Text format in JTextArea
    By goodlily in forum AWT / Swing
    Replies: 4
    Last Post: 04-11-2011, 12:57 AM
  5. Format Specifiers
    By Cass29 in forum New To Java
    Replies: 3
    Last Post: 12-20-2009, 04:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •