Enclosing character constants in single quotes works for most printing characters, but a few characters, such as the carriage return, pose a special problem when a text editor is used. In addition, certain other characters, such as the single and double quotes, have special meaning in Java, so you can not use them directly. For these reasons, Java provides special escape sequences, sometimes referred to as backslash character constants. These sequences are used in place of the characters that they represent. For example, this assign sch the tab character:
ch = '\t';
The next example assigns a single quote toch:
ch = '\'';
Java supports one other type of literal: the string. A string is a set of characters enclosed by double quotes. For example,
"this is a test"
Friday, December 14, 2018
Character Escape Sequences and String Literals
December 14, 2018
No comments
Escape Sequence Description
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment