Chapter 4.3 Characters Flashcards
Character definition
A character is a single character.
A character literal is enclosed in matching single quotes (‘).
ex.
char letter = ‘A’;
char numChar = ‘4’;
ASCII code values in decimal and unicode for characters ‘0’ to ‘9’
48-57
\u0030 to \u0039
char numChar = (char)52; // ’4’
ASCII code values in decimal and unicode for characters ‘A’ to ‘Z’
65-90
\u0041 to \u005A
char letter = (char)65; // ’A’
\
ASCII code values in decimal and unicode for characters ‘a’ to ‘z’
97-122
\u0061 to \u007A
How many bytes does unicode take
What is the range of the highest to lowest unicode value
two bytes
‘\u0000’ to ‘\uFFFF’
Escape character for Characters: backspace
\b
\u0008
8
Escape character for Characters: tab
\t
\u0009
9
Escape character for Characters: linefeed
\n
\u000A
10
Escape character for Characters: formfeed
\f
\u000D
13
Escape character for Characters: carriage return
\r
\u000D
13
Escape character for Characters: backlash
\u005C
92
Escape character for Characters: double quote
"
\u0022
34
char ch = ‘a’;
ch++;
System.out.println(ch);
what prints?
b
How to convert a character to an int type to perform character arithmetic
c = (char) (c+1);
Given the statement
char x = ‘7’;
then the statement
int i = (int)(x - ‘0’);
what is the value of i
will assign to i the value 7 because the difference between the encoding of ‘7’ and the encoding of ‘0’ is 7.