Java operator summary

The following is a summary of Java operators:

1、 Arithmetic operator

Note: it is not recommended to use + + and C inside other expressions, which is very confusing

example:

Supplement:

2、 Logical operator

Summary: (false false, true true)

And: a false is a false or: a true is a true XOR: the difference is true or not: take the inverse short circuit and: first calculate the expression on the left, which is true, and then calculate the expression on the right. Otherwise, the expression on the right does not need to be calculated, and the result is a false short circuit or: also calculate the expression on the left first. When it is true, the expression on the left does not need to be calculated, and the result is true

3、 Bitwise operator

example:

Summary:

Shift left: equivalent to the power of the number of moving bits multiplied by 2. Shift right: equivalent to the power of the number of moving bits divided by 2

Move right to fill the position. The highest value of the original data is fixed. Fill the number of the original high position, move right without sign, and fill the empty positions with 0

4、 Assignment operator '='

Int num = 22 / / assign 22 to num

5、 Extended assignment operator

6、 Operator priority

[Note: no need to remember, just add parentheses when writing]

7、 Ternary operator

Boolean expression? Expression 1: expression 2 returns the value of expression 1 if the value of Boolean expression is true. Returns the value of expression 2 if the value of Boolean expression is false

example:

1>5 ? 1: 2 / / result: 2

8、 Comparison operator

9、 Mathematical function (math class in Java)

Math class: contains a variety of mathematical functions

I hope the above summary of Java operators is helpful to friends in need

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>