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