java common operators

Arithmetic Operator

  1. +: Addition-the values ​​on both sides of the addition operation, for example a+b=5
  2. -: Subtraction-the left operand subtracts the right operand, for example ab=3
  3. ×: Multiplication-the values ​​on both sides of the multiplication operator, for example a*b=20
  4. /: Division-divide the left operand by the right operand, for example a/b=5
  5. %: Take the remainder-the left operand divided by the right operand, for example a%d=1
  6. ++: Increment-the operand increases by 1, such as a++, ++a
  7. –: decrement-the operand is reduced by 1, such as a--, --a

The following example operation
Insert picture description hereresults are
Insert picture description here

Relational operator

  1. ==: Check if the values ​​of the two operands are equal, for example (a==a) is true

  2. ! =: Check if the values ​​of the two operands are not equal, for example (a!=b) is true

  3. > Check whether the value of the left operand is greater than the value of the right operand, for example (a>b) is true

  4. <: Check whether the value of the left operand is less than the value of the right operand, for example (a<b) is false

  5. <=: Check whether the value of the left operand is less than or equal to the value of the right operand, for example (a<=b) is false

  6. >=: Check whether the value of the left operand is greater than or equal to the value of the right operand, for example (a>=b) is true

The following example operation
Insert picture description hereresults are
Insert picture description here

Short-circuit logic operator

  1. &: and-return true before and after it is correct, and return false if one of them is wrong
  2. |: Or-there is a correct return true before and after, and false returns are both false
  3. ! : Non-return true if followed by an error, false if it is correct
  4. &&: Similar to &, but not executed directly after the previous error (usually it is not possible to write a/0, but as long as the previous error is run, the latter will not be executed directly (short circuit))
  5. ||: Similar to |, but the front is correct and the back is not executed directly
    (similar to &&)

The following example operation
Insert picture description here

The result is

Insert picture description here

Guess you like

Origin blog.csdn.net/s001125/article/details/109751681