29.12. Printing Literals and Escape Sequences

Most literal characters to be printed in a printf statement can simply be included in the format string. However, there are several “problem” characters, such as the quotation mark (") that delimits the format string itself. Various control characters, such as newline and tab, must be represented by escape sequences. An escape sequence is represented by a backslash (\), followed by an escape character. Figure 29.23 lists the escape sequences and the actions they cause.

Figure 29.23. Escape sequences.
Escape sequenceDescription
\' (single quote)Output the single quote (') character.
\" (double quote)Output the double quote (") character.
\\ (backslash)Output the backslash (\) character.
\b (backspace) ...

Get Java™ How to Program, Seventh Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.