Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Detailed explanation of Java operator precedence

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the knowledge of "Java operator priority explanation". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Detailed explanation of 1.Java operator precedence

Priority refers to the execution and order of multiple operators in the same formula, and operators in the same level have the same priority. The operation symbols with the same priority meet each other, and the operation order is determined according to associativity. The operators are listed below from high to low. Operators on the same line have the same precedence.

. [] () associativity from left to right

+ + -! ~ binding from left to right

* /% binding from left to right

+-binding from left to right

Binding from left to right

= binding from left to right

=! = binding from left to right

& combination from left to right

^ associativity from left to right

& & combination from left to right

| binding from left to right |

?: combination from right to left

= binding from right to left

For example, for the expression: a=b+c*d/ (c ^ d), because parentheses have the highest priority, c ^ d is calculated first, then c ^ d, then divided by c ^ d, and finally, the above result and the sum of b are stored in the variable a.

2: integer operator

Integer operators can be divided into unary and binary types according to the number of operands. Unary operators operate on one variable at a time, and binary operators operate on two variables at a time. For operations, if a variable or Operand is a long integer, then the result must be a long integer, otherwise, even if the Operand has not been determined to be a byte, short integer, or character, the result is an integer. The following table is a unary operator.

Example of a practical operation of an operator

-change the integer symbol-I

~ bit operation: non ~ I

+ + plus 1 iTunes +

-- minus 1 iMui-

Note: the unary inverse operator (-) is used to change the positive and negative sign of the integer, bit by bit to change all the bits of the variable into 0, the bit of 0 into 1, and add and subtract (+, -) add or subtract the value of the variable.

Here is a concrete example:

Int iTunes 0

Int jung1

For move to the right a > > b

Move to the right a > b

Note: the basic function of > > and > is to move to the right, but > > is to fill the vacancy left by moving right with symbol bits, and > is to fill the vacancy left by moving right with zero.

There is also a class of operations, such as: Jmurmuri, where-= is a composite operation of binary operation-and assignment operation =, which is equivalent to j=j-i, which applies to all binary operators.

Here are several points about the integer operation to further explain, first, the integer division is rounded to the direction close to 0; secondly, if you divide by 0 or take the module to 0, the program will be forced to stop at run time, if your operation results exceed the minimum limit, or underflow, the result will be 0, if the maximum limit is exceeded, it will lead to the rewinding of the result.

3: Boolean operator

There are other operators that produce Boolean results, which we call Boolean operators, which are listed in the following table.

Example of a practical operation of an operator

< 小于 a >

Greater than a > b

= b

= = equal to astatb

! = is not equal to axiomatic

What I want to point out here is that the equality operator = = may cause you a lot of trouble. many people often misuse the equal sign = when comparing two values, so it becomes an assignment operation. so be sure to pay attention to the = = when comparing values in programming. The Boolean type itself has several logical operators that can operate on Boolean data:!, &, / /

In fact, if you think of the Boolean value true as equivalent to 1 and false as 0, then the law of integer operation applies to Boolean types for the same operator.

There is also a ternary operator in the Boolean operator, which has the following format:

Operand? Statement1:Statement2

In this formula, the true or false of Operand is calculated first, if true, Statement1 is executed, and if false, Statement2 is executed. The following code gives an example of this operation:

(a > b)

This expression will return the larger value in an and b.

4: floating-point operator

The traditional floating-point binary operation makes the floating-point value equivalent to integer division in addition to the assignment operator (+ =, -. * =. /) modulo (%) and modular assignment (% = 0). Similarly, + and-- increase or decrease the value of the variable by 1.

Similar to integer variables, the result is placed in the type of maximum length. If the operation includes two floating-point types, the result is also a floating-point type. If one or more of them are double-precision floating-point type, the result is double-precision floating-point type. When you use the relational operator: >, =,

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report