007_ integer type

Source: Internet
Author: User

One, the data type in Java:

  

Ii. scope of expression of each type

  

Type

Occupy Storage space

Table Count Range

Byte

1 bytes

-27~27-1 ( -128~127)

Short

2 bytes

-215 ~ 215-1 ( -32768~32767)

Int

4 bytes

-231 ~ 231-1 ( -2147483648~2147483647) approx. 2.1 billion

Long

8 bytes

-263 ~ 263-1

Three, three representations of the Java language integer constants:

A) a decimal integer, such as: 99,-500, 0.

b) An octal integer that requires a 0 start, such as: 015.

c) Hexadecimal number, requires 0x or 0X beginning, such as: 0x15.

Iv. Test Data Program

 Public classTestdatatype { Public Static voidMain (string[] args) {//[√] since 10 in 2 of the 31 square ~ 2 of the 31-1 this range class        inta=10; /*[X] because 5555555555 does not-2 of the 31-square-2 of the 31-square-1 This range class (about the plus or minus 2.1 billion or so) the literal 5555555555 of type int is an out of range */        intb=5555555555; //[√] since 20 in 2 of the 7-square ~ 2 of the 7-1 this range class ( -128~128-1)        CharC=20; //[X] because 200 does not-2 of the 7-square-2 of the 7-time Square-1 This range class ( -128~127)        Chard=200; //[√]declares a long type, plus l at the end        Longe=5555555555l; }}

  Note: The initial period of the automatic type conversion is that the number of conversions must be within the stated range of its type and the range of data types after conversion must be greater than the range of data types of the converted number, otherwise compile errors or loss of precision

007_ integer type

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.