Specifications

Sun Services
Java™ Programming Language
Module 9, slide 14 of 37
Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision F
Simple Formatted Output
You can use the formatting functionality as follows
out.printf(“name count\n”);
String s = String.format(“%s %5d%n”, user, total);
Common formatting codes are listed in this table.
Code Description
%s Formats the argument as a string, usually by calling the
toString method on the object.
%d %o %x Formats an integer, as a decimal, octal, or hexadecimal value.
%f %g Formats a floating point number. The %g code uses scientific
notation.
%n Inserts a newline character to the string or stream.
%% Inserts the % character to the string or stream.