The char type represents a single character type, and any data enclosed in single quotation marks is a representation of a character. A character can have only one character.
Note: escape sequences for special characters: escape characters
An overview of escape characters:
Special characters use "\" to convert it to the output of the character itself, and the character "\" is called a transfer character.
Requirements: Use the output statement to print out quoted information such as output.
SYSTEM.OUT.PRINTLN ("Teacher said" Java is fun "), compilation does not pass properly. syntax has errors, the compiler reads the second quotation mark is considered the end of the string, the remaining do not know how to handle. How to solve this problem: use escape characters in Java to represent special characters. An escape character begins with a backslash (\).
problem: If you want to print a quoted string, you can use the backslash (\) followed by the character, which is the escape character.
Escape character |
Name |
Unicode |
\b |
Backspace (BACKSPACE) |
\u0008 |
\ t |
Tab ( Tab keyboard) |
\u0009 |
\ n |
linefeed (line wrapping) |
\u000a |
\ r |
Carriage Return (carriage return) |
\u000d |
\\ |
Backslash (back slash) |
\u005c |
\‘ |
Single Quote (single quotation mark) |
\u0027 |
\" |
Double Quote (double quotes) |
\u0022 |
\ r means accept keyboard input, equivalent to press ENTER.
\ n indicates a line break.
\ t tab, equivalent to table key
\b Backspace key, equivalent to back Space
\ ' Single quotation mark
\ ' double quotes
\ \ represents a diagonal cross
Solve the above question: System. out. println ("Teacher Said\" Java is fun\ "");
Note: The line break is another line, the carriage return is the beginning of a line, so we usually write a file carriage return should be exactly called carriage return line break
JAVA Char Type