// This works only in JDK 1.5+
import static java.lang.System.out;

// ...

int c = 65;

// printf works much like a Fortran FORMAT or C printf.
// %2x means insert first parameter here in a field 2 chars wide in hex.
// %3d means insert next parameter here in a field 3 characters wide in decimal.
// %1c means insert next parameter here in a field 1 wide as a Unicode character.
// Everything else, including the [] and :s are just decorative text.
// For even more % codes, scroll down.

out.printf( "result is: [%2x] : %3d : %1c\n", c, c, c );

// prints : result is:_[41]_:__65_:_A

// In JDK 1.4- you would code that as:
out.println( "result is: ["
                    + ST.leftPad( Integer.toHexString( c ), 2 )
                    + "] : "
                    + ST.leftPad( Integer.toString( c ), 3 )
                    + " : "
                    + (char) c);

// The JDK 1.5 code is considerably easier to write and proofread, but the 1.4 code is faster.

// Possible codes you might use include:
//
// %b boolean
// %h hashcode of the value. NOT hex!!
// %s String
// %c Unicode character
// %d decimal integer
// %o octal integer
// %x hex integer, %02x pads to 2 chars with lead zeroes.
// %e floating point scientific notation with exponent.
// %f floating point as a decimal number without exponent.
// %g general format %e or %f depending on size.
// %a precise hex floating number.
// %t date/time
// %% a literal %
// %n line separator, a  platform-specific line separator, not necessarily \n.
// %0d left pad with 0
// %,d group with commas
// %-d left justify
// %+d explict sign, + or -.
// %% literal %
// see documentation on java.util.Formatter for a complete list and the full syntax.

// Use of G format:

// %[flags][min width of field].[number of significant digits of precision (not # of decimal places)]g
out.printf( "value is %4.3g\n", 1.4d );        // prints value is 1.40
out.printf( "value is %4.3g\n", 1.456d );      // prints value is 1.46
out.printf( "value is %4.3g\n", 145.0d );      // prints value is _145
out.printf( "value is %8.4g\n", 1.5d );        // prints value is ___1.500
out.printf( "value is %4.4g\n", 1.5E-6 );      // prints value is 1.500e-06
out.printf( "value is %,8.6g\n", 12345.0d );   // prints value is 12,345.0