1, Java, char accounted for 2 bytes, 16 bits. Can be stored in Chinese characters
2, Char assignment
Char a= ' a '; Any single character, plus single quotes.
Char a= ' in ';//any single text, plus single quotes.
Char a=111;//integer. 0~65535. Decimal, octal, hexadecimal can be. The corresponding character in the Output character encoding table.
Note: Only single characters can be placed.
3, char operation
The char type can be calculated because Char has a corresponding numeric value in the ASCII and other character encoding table.
In Java, when the char type character runs, it is treated directly as an integer corresponding to the ASCII table.
Example:
Char m= ' a '; --a.
Char m= ' a ' + ' B '; --ã. The char type is added, promoted to type int, and the corresponding character is output. Note that the output from the CMD.exe is a problem, and different coded outputs are displayed differently. Eclipse must be changed into UTF-8.
int m= ' A ' + ' B '; --195. 195 does not exceed the int range, direct output 195.
Char m= ' a ' +b; --error. Because B is a variable that is assigned a value.
Char m=197; --ã. The corresponding character in the Output character encoding table.
Char m= ' 197; --error. Because there is a single quote, the representation is a character and only a single character is allowed.
Char m= ' a ' +1; --b. to an int, the corresponding character of the result 98 is B.
Char m= ' in ' + ' country '; --42282.
Char m= ' in ' + ' country ' + ' country ' + ' country '; --error. int turns char has a loss. Because the result has exceeded the range of the char type.
int m= ' in ' + ' country ' + ' country ' + ' country '; --86820
Char m= ' in ' +1; --丮. 1 is int, the result is promoted to int, the corresponding character is output.
Char m= ' in ' + ' country '; --error. String cannot be converted to char.
System.out.println (' Middle ' + "country"); --China. A procedure that has no value attached to a variable. string is connected to any character by "+" and converted to string.
Summary:
With single quotes ' identity, only a single character can be placed.
The char+char,char+int--type is raised to int, with the value char variable, and the corresponding character in the character encoding table is output.