JAVA learning - Operators

 在学习了常量变量的基础上,今天开始学习运算符。

Operators: Symbols of constants and variables of the arithmetic operation, the operator to use the program calculates the data

Common operators are: arithmetic operators, assignment operators, relational operators, logic operators, ternary operator.

Arithmetic operators
common arithmetic operators are: + adding, - subtraction, * multiplication / division, modulo arithmetic%, increment 1 + - - 1 decrement Here Insert Picture Descriptioninteger and floating-point operations, the results also as a floating point type
+: when numeric data, while adding the plus sides. 'a', '0' character data and the like involved in computing, calculates numerical values of the character represented in the computer.
Plus either side on both sides there is a splicing a string, the string
Here Insert Picture Description
increment (+) and decrement (- -) Operation:
When used alone, the results are the same before and after on the variable.
When involved in computing:

  • Placed before a variable, from the first increase (decrease), during other operations.
  • After variables on first original value to perform other operations, and then from the increase (decrease).
    Here Insert Picture DescriptionAssignment operator
    common assignment operator are: =, + =, - =, / = * =,% =
    benefits: omitted casts
    Here Insert Picture Description

Relational Operators
calculation result relational operators are Boolean, true or false
common relational operators are: ==, =,>,> =, <, <=!
Here Insert Picture Description
Logical operator
common logical operators are: && (logical aND), || (logical oR),! (Logical NOT)
operation result for the Boolean type.
Here Insert Picture DescriptionEven number! The results unchanged; odd! The results contrary.

Ternary operator
(relational expression)? Expression 1: Expression 2;
calculation process:

  • If the result of the expression is the result of the relationship between true, the operation expression 1
  • If the result of the expression is the result of the relationship false, operation expression 2

Here Insert Picture Description

Released nine original articles · won praise 1 · views 178

Guess you like

Origin blog.csdn.net/LQyh_/article/details/104037904