Escape+Characters

=Escape Characters=

Escape Characters:There are many escape characters but only a few you will need to know for the AP Computer Science Exam.

Escape Sequences
A character preceded by a backslash (\) is an //escape sequence// and has special meaning to the compiler. The following table shows the Java escape sequences:


 * Escape Sequences**||~ Escape Sequence ||~ Description ||
 * \t || Insert a tab in the text at this point. ||
 * \b || Insert a backspace in the text at this point. ||
 * \n || Insert a newline in the text at this point. ||
 * \r || Insert a carriage return in the text at this point. ||
 * \f || Insert a formfeed in the text at this point. ||
 * \' || Insert a single quote character in the text at this point. ||
 * \" || Insert a double quote character in the text at this point. ||
 * \\ || Insert a backslash character in the text at this point. ||

When an **escape sequence is encountered in a print statement**, the compiler interprets it accordingly. For example, if you want to put quotes within quotes you must use the escape sequence, \", on the interior quotes. To print the sentence

code She said "Hello!" to me.

code

you would write code System.out.println("She said \"Hello!\" to me."); code =**Videos**=

media type="youtube" key="oZF1z-4SJ1c" height="315" width="560" media type="youtube" key="ZN7Z2FNskXI" height="315" width="420"