aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes printf(String, Object) and  format(String, Object) methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "printf(String, Object) and  format(String, Object) methods" Watch "printf(String, Object) and  format(String, Object) methods" New topic
Author

printf(String, Object) and format(String, Object) methods

Steve Ng
Greenhorn

Joined: Aug 10, 2008
Posts: 17
Dear ranchers,

According to K&B book, the format string should be as follows:

[Array index] [Flags] [Width] [.Precision] [Conversion]

And the array index is starting from 1: 1$, 2$ ...

Flags: +, - , 0, , , (

Width: integer number

Conversion: b, c, d, s, f

My question is:

How many flags can be used in combination? I have tried and it seems to m that maximum only 2 flags in be used together.

For example: System.out.printf("%2$(010d*", "Hello", -200);

How does the compiler interpret the format string from left to right? For example: how does it differenciate between flags and width and conversion etc.

Thank you
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: printf(String, Object) and format(String, Object) methods
 
Similar Threads
Regarding printf() method
printf, multiple flags
How to convert old java I/O code to nio ...
printf method
Printing the index of an array