Java chapter II variables, data types, and operators
One , variable: a basic unit that stores data.
Second , the Declaration and assignment of variables:
1) Declare and assign values: Data type variable name = value ; Example:int price=1000;
2) Declaration, assignment is divided into two steps: Data type variable name ; Example: int price;
variable Name = value ; price=1000;
Three , the data type 2 kinds:
1) basic data type 8 kinds:
Byte length: - 128~127 ( -2 7 2 7 1 )
2 of the Short-2 , minus 1 in the four-time square .
The Int-2 of the two to 2 minus 1 .
The Long-2 of the Five-to -2 reduction of 1 99l
Float 99f
Doubles Double price=32.5;
Boolean True (true) False (false) bolean isbrand=true
Char one character , two byte range 0~65535 reference ASCII character encoding table Char sex= ' Male '; char num=65; ( output A)
2) Reference data type:
String strings name=" Zhang San ";
Class
Interface
Four , the variable naming specification:
English words or pinyin
Initials : Starts with letters, underscores, and$ ;
When multiple words are composed of variable names: Named by the Camel, example:studentname
The name of the variable should be the result of knowing the meaning of the name
assignment operator:= assigns the right value to the left
Six , arithmetic operators:+-*/% ( remainder )
Seven ,num++;//num=num+1;num+=1;
Num--;//num=num-1;num-=1;
System.out.println (--num);// calculate and re-output first (++num same )
System.out.println (num--);// Output recalculation First (num++ same )
Eight ,double avg= (90+99)/3.0 Automatic type conversion occurs
the conditions for automatic type conversion ;
1) Type-compatible:(int and double are numeric )
2) The target type is greater than the source type
Ix. Coercion Type conversion: (data type) variable name (data type) value
Example:double num=5.5; int result= (int) num;
or int result= (int) 5.5;
Java chapter II variables, data types, and operator notes