- Regular arithmetic operators
Include + 、-、 *,/,% respectively corresponding to add, subtract, multiply, divide, take the remainder, the arithmetic operator to handle the two numbers must be the same type, if it is different type and can not be automatic type conversion words must be forced type conversion, but forced type conversion may lose some information, there are shorthand method + =, etc. As follows:
int i = i + 1;//up and down two equations are actually the same//the corresponding other operators also have such shorthand, such as *=
int i + = 1;
- Self-increment self-reduction
It should be known from the programming base that adding a minus one action to a variable in a program is very common, and the self-increment decrement operator simplifies this operation, and the difficulty in this part is the effect of the position of the self-increment operator on the variables in the program, and if the self-increment-decrement is used before the variable, After the variable is the first to use the re-operation, with the following examples to illustrate:
Public class Welcome { publicstaticvoid main (string[] args) { int A = 1; int b = 1; Output results 2, 2, 1, 2
System.out.println (+ +a); System.out.println (a); System.out.println (b+ +); System.out.println (b); } }
include = =, <, >, >=, <=, which are used to compare size or equality, as in written use.
Includes &, &&, |, | |,!, where & and | can also be used as bitwise operators, as logical operators when both elements are Boolean,&& and | | Functions, like & and |, are short-circuit logic, that is, the first operand is sufficient to determine the value of an expression without a second operand, and most of the time it uses a short-circuit logic operation.
Another common logical operation is the ternary expression, which is the expression? Result 1: Result 2, the expression is true returns result 1, and false returns result 2, for example x<y?x:y that returns the smaller values in X and Y.
Looking back, Java restudying (vii): operator of Java Basics