Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By JBelg

Thread: Error with Print Format Specifiers

  1. #1
    Join Date
    Mar 2011
    Posts
    93
    Rep Power
    0

    Default Error with Print Format Specifiers

    Hello. I wrote a simple program to take user input (positive integers only) and output an average. I thought an average of integers could be a decimal number, so I cast the average as a double. I used a print format specifier in my output line:

    System.out.printf("The average is: %1.3f" + average);

    But I get an error: "Exception in thread "main" java.util.MissingFormatArgumentException: Format specifier '1.3f'

    Can anyone tell me the correct way to include a format specifier in my print output statement?

    Thanks

  2. #2
    JBelg is offline Member
    Join Date
    Oct 2012
    Posts
    36
    Rep Power
    0

    Default Re: Error with Print Format Specifiers

    The +(plus) has to be a ,(comma).

    You gave it the correct format, but you didn't give anything to format.
    DarrylBurke likes this.

  3. #3
    Join Date
    Mar 2011
    Posts
    93
    Rep Power
    0

    Default Re: Error with Print Format Specifiers

    Hello. Aha!! Problem solved. Thank you for pointing that out.

Similar Threads

  1. Using Format Specifiers as Text in printf()
    By msphelix in forum New To Java
    Replies: 3
    Last Post: 08-27-2012, 05:28 PM
  2. Pls help to print string in given format
    By know.how in forum New To Java
    Replies: 2
    Last Post: 08-31-2011, 01:43 PM
  3. To print * in right angle format
    By venkatakrishnan in forum New To Java
    Replies: 9
    Last Post: 07-24-2011, 04:29 PM
  4. How to format the print statement
    By ftrengnr in forum New To Java
    Replies: 1
    Last Post: 09-18-2010, 10:02 PM
  5. Format Specifiers
    By Cass29 in forum New To Java
    Replies: 3
    Last Post: 12-20-2009, 03: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
  •