Char type __java in JAVA

Source: Internet
Author: User
Tags numeric value

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.