Operation rules of Java basic data types

Java basic type operation rules

1. Automatic type promotion

When the capacity is small and the capacity is large, the calculation is automatically upgraded to the large capacity data type

byte,char,short-->int-->long-->float-->double

When performing operations between byte, char, and short, use the int type as receiving

2. Forced type conversion

Need to use strong conversion. For example: double c1=10.5; int c2=(int)c1  

Forced type conversion may cause loss of precision. For example: short c1=128; byte c2=(byte)c1; System.out.println(c1); //The running result is: c1=-128.

 

Guess you like

Origin blog.csdn.net/tdongmu/article/details/108082160