<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # Java 中的算術運算符 > 原文: [https://javabeginnerstutorial.com/core-java-tutorial/java-arithmetic-operator/](https://javabeginnerstutorial.com/core-java-tutorial/java-arithmetic-operator/) 在本節中,我們將學習**算術**,**運算符**,**優先級**和**運算符關聯**。 ## 運算符優先級 *優先級*決定在同一計算中存在多個運算符的情況下,首先求值哪個運算符。 ## 運算符優先級表 | 運算符 | 優先級(從高到低) | | --- | --- | | 后綴 | `expr++ expr--` | | 一元 | `++expr --expr +expr –expr ~ !` | | 乘法 | `* / %` | | 加法 | `+ –` | | 移位 | `<< >> >>>` | | 關系 | `< > <= >= instanceof` | | 相等 | `== !=` | | 按位與 |`&` | | 按位異或 | `^` | | 按位或 | <code>&#124;</code> | | 邏輯與 | `&&` | | 邏輯或 | <code>&#124;&#124;</code> | | 三元 | `?:` | | 賦值 | <code>= += -= *= /= %= &= ^= &#124;= <<= >>= >>>=</code> | ## 優先級示例 ```java /* * Here we will see the effect of precedence in operators life */ class OperatorPrecedenceExample { public static void main(String args[]) { int i = 40; int j = 80; int k = 40; int l = i + j / k; /* * In above calculation we are not using any bracket. So which operator * will be evaluated first is decided by Precedence. As precedence of * divison(/) is higher then plus(+) as per above table so divison will * be evaluated first and then plus. * * So the output will be 42. */ System.out.println("value of L :" + l); int m = (i + j) / k; /* * In above calculation brackets are used so precedence will not come in * picture and plus(+) will be evaluated first and then divison()/. So * output will be 3 */ System.out.println("Value of M:" + m); } } ``` ## 運算符關聯性 如果兩個運算符在計算中具有相同的優先級,則將使用運算符的**關聯性**來決定首先執行哪個運算符。 ## 關聯性示例 ```java package jbt.bean; /* * Here we will see the effect of precedence in operators life */ public class OperatorAssociativityExample { public static void main(String args[]) { int i = 40; int j = 80; int k = 40; int l = i / k * 2 + j; /* * In above calculation we are not using any bracket. And there are two * operator of same precedence(divion and multiplication) so which * operator(/ or *) will be evaluated first is decided by association. * Associativity of * & / is left to right. So divison will be evaluated * first then multiplication. * * So the output will be 82. */ System.out.println("value of L :" + l); int m = i / (k * 2) + j; /* * In above calculation brackets are used so associativity will not come * in picture and multiply(*) will be evaluated first and then * divison()/. So output will be 80 */ System.out.println("Value of M:" + m); } } ``` ## Java 中的運算符 讓我們分別討論每個運算符。 賦值(`=`)和算術運算符(`+, -, *, /`)的工作方式與其他編程語言相同,因此在此不再贅述。 `/`和`*`運算符的優先級高于加法(`+`)或減法(`-`)或取模(`%`)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看