Precedence of operators in Java
The so-called priority is the order of operations in an expression. The precedence of operators commonly used in Java is shown in the following table:
650) this.width=650; "src=" http://img.mukewang.com/5360ffb90001b4f002620224.jpg "/>
Level 1 has the highest priority, and level 11 has the lowest priority . For example, the result of x = 7 + 3 * 2 is 13 "Multiply First and add"!
PS: We don't have to go. The order of precedence of the rote operators, which is typically used to assist in priority management in real-world development. For example:
650) this.width=650; "src=" http://img.mukewang.com/5361000a000129a005060071.jpg "/>
Analysis: Parentheses have the highest precedence, so
1, execute a + 18, the result is 30
2, perform (A + 18)% 4 modulo, the result is 2
3, execute A * ((A + 18)% 4), the result is 24
Code:
public class HelloWorld {
public static void Main (string[] args) {
int m = 5;
int n = 7;
int x= (m*8/(n+2))%m;
System.out.println ("M:" + M);
System.out.println ("N:" + N);
System.out.println ("x:" + x);
}
}
Operation Result:
M:5
N:7
X:4
This article is from "Ghost" blog, please make sure to keep this source http://caizi.blog.51cto.com/5234706/1547682
Java Foundation---Operator precedence in Java (16)