2016-06-28
1 Automatic conversion
The destination type is larger than the original type
The two types are mutually compatible
Byte->short
Short->int
Char->int
Int->long
Int->double
float->double float 4-byte single-precision double 8-byte dual-precision
One of the two numbers is of type double, the other is also converted to a double type, and the result is a double type;
Otherwise, one of the two numbers is a float type, and the other I is also converted to float type
Otherwise, if there is a long type in two operands, the other is also converted to a long type
Otherwise, two numbers are converted to int type
Package day08; Public class Testchange { publicstaticvoid main (string[] args) { Double adouble=3.55555; int aint= (int) adouble; System.out.println (aint); }}
2 Coercion of type conversions
Floating-point type to Integer: Truncate the decimal digit, preserving the integer digits
Long integer to short integer: Go to bit.
int 4 bytes 32 bits
Byte 1 bytes 8 bits
25700000000 00000000 00000001 00000001
Packageday08; Public classTestchange { Public Static voidMain (string[] args) {//double adouble=3.55555;//int aint= (int) adouble;// //System.out.println (aint); intaint=257; byteAbyte= (byte) aint; System.out.println (Abyte); }}
Resources
[1] Java Easy Start Classic tutorial "full version"
Java section No. 08 data type conversions