Zoo tutorials: [ SQL | Linux | XML ]
ProgZoo: [ Java | C# | VB | C++ | Perl ]
Log in

A Gentle Introduction to
Java Programming

Formatting Integers

 

Input and Output

Formatting Integers

1. [ Java ] Printing an integer


Big

The printf method takes a format string as the first parameter. This string is printed but following parameters replace the % placeholders.

%d is used for decimal numbers.

Format Code Meaning
Simple %dA simple decimal number
Right aligned %5dPrint right aligned in 5 characters. Fill any unused characters with spaces.
Leading zeroes %05dPrint right aligned in 5 characters. Fill any unused characters with zero.
Hexadecimal %xPrint as a hexadecimal (base 16) number.
With commas %,dUse , to separate thousands.