Basic data types of java
I. Integer type
1. Decimal
2. Gossip
The number of octal segments is 8 to 1, including 0 ~ Add a "0" before the integer to indicate the number of octal digits.
3. Hexadecimal
The hexadecimal number is full, and the value ranges from 0 to 1 ~ 9, ~ F, and add a "0x" before the integer to indicate the hexadecimal number.
II. Floating point
1. float: single-precision floating point number
When declaring a float-type floating point number, add F or f at the end.
2. double: double-precision floating point number
When declaring a floating point of the double type, add D or d at the end. The default floating point type is double, so D and d can also be excluded.
3. String (char)
Represents a character, 16 characters in two bytes
4. boolean)
Use true or false to indicate true or false
Type conversion
I. Free conversion
You do not need to explicitly specify the type to be converted. Instead, it is automatically converted by the Java virtual machine.
II. Forced conversion
It is mandatory and cannot be automatically converted, but mandatory. Precision is lost.
III. Implicit conversion
Similar to automatic conversion, the Java virtual machine determines whether the data type can be loaded based on the number of digits of the data type.
Operator
Arithmetic operators
"+": Addition operator. It can also be used for character join.
"-": Subtraction operator
"*": Multiplication operator
"/": Division operator
"%": Returns the remainder operator.
Relational operators
"=": Equal
"! = ": Not equal
"> =": Equal to or greater
"<=": Indicates less than or equal
">": Greater
"<": Indicates less
Logical operators
"&": Operator
"|": Or operator
"! ": Non-operator
Ternary operators
Expression 1? Expression 2: Expression 3
When expression 1 is true, the result is the value of expression 2. Otherwise, the result is the value of Expression 3.
Bitwise operators
"&": Bitwise AND operator
"|": Bitwise OR operator
"^": Bitwise XOR operator
Displacement operator
">>": Shifts the right operator with symbols
"<": Shifts the left operator with symbols.
">>>": Unsigned right shift operator
Value assignment operator
"=": Value assignment
Process control
Condition Statement
If (expression) {method body} else if (expression body) else {method body}
Abbreviated form: if...
General format: if... else...
Complete format: if... else
Branch statement
Switch (expression)
{
Case expression 1:
{
Method body
Break;
}
Case expression 2:
{
Method body
Break;
}
Default:
Method body
}
Loop statement
While loop statement
While (expression)
{
Method body
}
Do... while loop statement
Do
{
Method body
}
While (expression)
For loop statement
For (variable initialization, expression, incremental expression)
{
Method body
}
Method of interruption loop
1: break: interrupt statement execution
2: continue: the statement jumps out of this loop and continues to execute the next loop.