Java char data type

자바 캐릭터 타입에 대한 내용입니다..

A char is a single character, that is a letter, a digit, a punctuation mark, a tab, a space or something similar. A char literal is a single one character enclosed in single quote marks like this

char myCharacter = ‘g’;

Some characters are hard to type. For these Java provides escape sequences. This is a backslash followed by an alphanumeric code. For instance ‘\n’ is the newline character. ‘\t’ is the tab character. ‘\\’ is the backslash itself. The following escape sequences are defined:

\b backspace
\t tab
\n linefeed
\f formfeed
\r carriage return
\” double quote, “
\’ single quote, ‘
\\ backslash, \

The double quote escape sequence is used mainly inside strings where it would otherwise terminate the string. For instance

System.out.println(“And then Jim said, \”Who’s at the door?\””);

It isn’t necessary to escape the double quote inside single quotes. The following line is legal in Java

char doublequote = ‘”‘;

답글 남기기

이메일은 공개되지 않습니다. 필수 입력창은 * 로 표시되어 있습니다.