Integer type:
Model 1.byte: 8-bit (1-byte) range: -128~127
Usage: byte x = 35;
Model 2.short: 16-bit (2-byte) range: -32768~32767
Usage: short x = 999;
Model 3.int: 32-bit (4-byte) default integer type
Usage: int x = 8;
Type 4.long: 64 bits (8 bytes) followed by "L" or "L", in order to distinguish the number "1", we use "l"
Usage: long x = 89L;
Floating-point types:
Type 1.float: single-precision floating-point type, 32-bit (4-byte) followed by "F" or "F"
Usage: float x = 3.14F; float y = 5.667f;
Type 2.double: Double-precision floating-point type, 64-bit (8-byte) default floating-point type
Usage: Double x = 23.666;
Character type:
Char Type: single character, 2 bytes, single quote
Usage: char x = ' a ';
Boolean type:
Boolean: Logical type, only true and false two values
Usage: boolean x = true; Boolean y = false;
Conversions between data types:
1. Automatic conversion (implicit conversion): Compatible
Usage: byte→short→int→long→float→double
range from small to large for automatic conversion
2. Cast:
Usage: (data type to convert) variable name;
int h = (int) 1234L;
Example:
practice in the package class; Public classdata type Conversion { Public Static voidMain (string[] args) {intA = - ; intb =9; floatg, H; G= A/b; System. out. println ("A/ B ="+g); H= (float) A/b;//Forced ConversionsSystem. out. println ("A/ B ="+h); }}
When two integers are divided, the number after the decimal point is truncated, and the result of the operation remains an integer, which is required to be cast;
As long as one of the integers is converted to a decimal type;
★java Syntax (ii) —————————— data types and load Exchange