Java Reference
In-Depth Information
The Enter (or return) key on your keyboard cannot be part of the string—in program-
ming code, a string cannot be broken into more than one line by using the Enter (return)
key.
Recall that the newline character is \n , which moves the insertion point to the beginning
of the next line. In Java, there are many other escape sequences that allow you to control
the output. Table 2-5 lists some of the commonly used escape sequences.
TABLE 2-5 Commonly Used Escape Sequences
Escape Sequence
Description
\n
Newline
Cursor moves to the beginning of the next line
\t
Tab
Cursor moves to the next tab stop
\b
Backspace
Cursor moves one space to the left
Cursor moves to the beginning of the current line
(not the next line)
\r
Return
\\
Backslash
Backslash is printed
\'
Single quotation
Single quotation mark is printed
\"
Double quotation
Double quotation mark is printed
Example 2-23 shows the effect of some of these escape sequences.
EXAMPLE 2-23
The output of the statement:
System.out.println("The newline escape sequence is \\n");
is:
The newline escape sequence is \n
The output of the statement:
System.out.println("The tab character is represented as \'\\t\'");
is:
The tab character is represented as '\t'
Search WWH ::




Custom Search