Priority order of arithmetic operators in Java: unary operators ( , --) multiplication and division operators (*, /, %) addition and subtraction operators ( , -)
Priority order of arithmetic operators in Java
Answer:
In Java, Arithmetic The priority order of operators is as follows:
1. Unary operators
2. Multiplication and division operators
3. Addition and subtraction operators
Expand answer:
Unary operators have the highest precedence, which means they are executed first. For example:
<code class="java">int num = 10; int result1 = ++num; // result1 = 11, num = 11 int result2 = -num; // result2 = -11</code>
Next, the multiplication, division, and modulo operators have higher precedence. For example:
<code class="java">int num1 = 10; int num2 = 3; int result3 = num1 * num2; // result3 = 30 int result4 = num1 / num2; // result4 = 3 int result5 = num1 % num2; // result5 = 1</code>
Finally, addition and subtraction operators have lower precedence. They are executed after all other operators. For example:
<code class="java">int num3 = 10; int num4 = 5; int result6 = num3 + num4; // result6 = 15 int result7 = num3 - num4; // result7 = 5</code>
Note:
The above is the detailed content of Arithmetic operator precedence order in java. For more information, please follow other related articles on the PHP Chinese website!