O'Reilly logo

Java™ How to Program, Seventh Edition by P. J. Deitel - Deitel & Associates, Inc., H. M. Deitel - Deitel & Associates, Inc.

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

29.10. Using Flags in the printf Format String

Various flags may be used with method printf to supplement its output formatting capabilities. Seven flags are available for use in format strings (Fig 29.14).

Figure 29.14. Format string flags.
FlagDescription
-(minus sign)Left justify the output within the specified field.
+(plus sign)Display a plus sign preceding positive values and a minus sign preceding negative values.
spacePrint a space before a positive value not printed with the + flag.
#Prefix 0 to the output value when used with the octal conversion character o. Prefix 0x to the output value when used with the hexadecimal conversion character x.
0 (zero)Pad a field with leading zeros.
, (comma)Use the locale-specific thousands separator (i.e., ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required