Dark Horse programmer-java basics-Basic Knowledge (2), dark horse java
------ Android training, java training, and hope to communicate with you! ------
I. Operators in java
In java, operators can be classified into-Arithmetic Operators, value assignment operators, comparison operators, and bitwise operators.
1. Arithmetic Operators
Arithmetic Operators are used in mathematical expressions. They play the same role as in mathematics.
| Operator |
Description |
Example |
| + |
Values on both sides of the addition-addition Operator |
A + B |
| - |
Subtraction-left operand minus right operand |
A-B |
| * |
Multiplication-values on both sides of the multiplication Operator |
A * B |
| / |
Division-left operand divided by right operand |
B/ |
| % |
Modulo-remainder of the left operand |
B % |
| ++ |
Auto-increment-the operand value is increased by 1 |
B ++ or ++ B |
| -- |
Auto-Subtract-the operand value is reduced by 1 |
B-or -- B |
For example:
Public class Test {
Public static void main (String [] args ){
Int a = 60;
Int B = 30;
Int c = 20;
Int d = 20;
Int e = 20;
Int f = 20;
System. out. println ("a + B =" + (a + B ));
System. out. println ("a-B =" + (a-B ));
System. out. println ("a * B =" + (a * B ));
System. out. println ("a/B =" + (a/B ));
System. out. println ("a % B =" + (a % B ));
// ++ I (f = "+ () indicates that after using the I variable, the I value is added (subtracted) 1;
System. out. println ("Before calculation c =" + c + ";" + "in calculation c ++ =" + (c ++) + "; "+" c = "+ c );
System. out. println ("e =" + e + ";" + "e) +"; "+" e = "+ e );
}
}
After compilation, It is shown as follows:
2. Value assignment operator
| Operator |
Description |
Example |
| = |
A simple value assignment operator assigns the value of the right operand to the left operand. |
C = A + B will assign the value obtained by A + B to C |
| + = |
The addition and value assignment operator that adds the Left and Right operations to the left operations. |
C + = A is equivalent to C = C + |
| -= |
Subtraction and value assignment operator, which subtract the Left and Right operands and assign them to the left operands |
C-= A is equivalent to C = C- A |
| * = |
Multiplication and value assignment operator, which multiply the Left and Right operands and assign a value to the left operand |
C * = A is equivalent to C = C * |
| /= |
Division and value assignment operator, which separates the Left and Right operations and assigns the value to the left operations. |
C/= A is equivalent to C = C/ |
| (%) = |
Modulo and value assignment operator. It modulo the Left and Right operands and assigns them to the left operands. |
C % = A is equivalent to C = C % |
| <= |
Left shift assignment operator |
C <= 2 is equivalent to C = C <2 |
| >>= |
Right shift assignment operator |
C> = 2 is equivalent to C = C> 2 |
| & = |
Bitwise AND value assignment operators |
C & = 2 is equivalent to C = C & 2 |
| ^ = |
Bitwise exclusive OR value assignment operator |
C ^ = 2 is equivalent to C = C ^ 2 |
| | = |
Bitwise OR value assignment operator |
C | = 2 is equivalent to C = C | 2 |