Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / March 2006

Tip: Looking for answers? Try searching our database.

Is there a printf(String s) method?

Thread view: 
KAR120C - 16 Mar 2006 01:42 GMT
I was wondering why the printf statement works in the following program:

/* Test.java --tests printf method */

public class Test{
    public static void main(String[] args){
         String string = "Test string";
       
         System.out.printf(string);
    }
}

The java 5.0 documentation only gives two printf methods for PrintStream:  

printf(String format, Object... args)

and

printf(Locale l, String format, Object... args).

I don't see one of the form:

prinf(String s).

Let me know if you can explain this?  Thanks.
Patricia Shanahan - 16 Mar 2006 06:04 GMT
> I was wondering why the printf statement works in the following program:
>
[quoted text clipped - 21 lines]
>
> Let me know if you can explain this?  Thanks.

"The number of arguments is variable and may be zero.". You have a
format string with zero codes, and a length zero list of Object arguments.

If you change string's declaration to:

   String string = "Test string %d";

you will see the MissingFormatArgumentException which confirms string is
the format.

Patricia
KAR120C - 17 Mar 2006 00:16 GMT
Good point!  Thx

>> I was wondering why the printf statement works in the following program:
>>
[quoted text clipped - 13 lines]
>
>Patricia


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.