<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>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # Java 語句初學者教程 > 原文: [https://javabeginnerstutorial.com/core-java-tutorial/java-statements-tutorial-for-beginners/](https://javabeginnerstutorial.com/core-java-tutorial/java-statements-tutorial-for-beginners/) 在這里,我們將學習 Java 語句。 ## Java 語句的類型 * 表達式語句 * 控制語句 * 賦值語句 在本節中,我們將討論控制語句。 * * * ## 控制語句 * 條件執行 * 循環控制 * 流控制語句 * * * ## 條件執行的類型 * `If`語句 * `If-Else`語句 * `If-Else-if`語句 * `switch`語句 * * * ### `if`語句 Java 中的`if`語句**包含僅在應用條件為`true`的情況下才執行的部分代碼**。 `if`語句僅接受**布爾表達式**作為條件。 > 與其他語言不同,Java 不接受數字作為條件運算符。 它僅將*布爾表達式*視為返回`TRUE`或`FALSE`的條件。 #### `If`語句的語法 ```java if (true) System.out.println("Hello! This will always get printed"); ``` ```java if (Boolean Expression) { Code block to get executed } ``` `If`語句的示例代碼 ```java public class if_condition { public static void main(String[] args) { String string = "Hello"; if ("Hello".equals(string)) { System.out.println("String has the Value Hello"); } if ("Hi".equalsIgnoreCase(string)) { System.out.println("String has the value Hi"); } } } ``` 如果運行上面的代碼,它將顯示“字符串具有值`Hello`”。 * * * ### `else`語句 `if-else if`語句含有多個`if`條件和`else`語句。如果條件為真,包含的代碼會被執行,如果條件為假,則將檢查下一個條件。 如果下一個`if`條件為`true`,則將執行包含的代碼,否則將執行代碼的`else`部分。 `if else if`語句僅采用**布爾表達式作為**有效條件。 > 與其他語言不同,java 不接受數字作為條件運算符。 它僅將*布爾表達式*視為返回`TRUE`或`FALSE`的條件。 > 例如,`if(1 == 1)`被接受,因為它是布爾表達式,將返回`true`。 `if(x = 1)`語句在 Java 中是不允許的。 #### `if-else`語句的語法 ```java if (1==2) System.out.println("Hello! This will not get printed"); else System.out.println("Hello! This will get printed"); ``` ```java if (Boolean Expression) { Code block to get executed } else{ code block to get executed when above condition is false } ``` `If Else`語句的示例代碼 ```java public class if_condition { public static void main(String[] args) { String string = "Hello"; if ("Hello".equals(string)) { System.out.println("String has the Value Hello"); } else { System.out.println("String is not Hi"); } if ("HI".equals(string)) { System.out.println("String has the Value Hi"); } else { System.out.println("String is not Hi"); } } } ``` 當您運行上面的代碼時,它將打印出來。 ```java String has the Value Hello String is not Hi ``` * * * ### `if-else if`語句 `if-else if`語句由多個`if`條件和`else`語句組成。 如果*條件*為真,則將執行隨附的代碼。 如果`if`條件為假,則它將檢查下一個`if`條件。如果下一個條件為真,則將執行附帶的代碼,否則將執行代碼的`else`部分。 `If Else If`語句僅將**布爾表達式**視為有效條件。 > 與其他語言不同,Java 不接受數字作為條件運算符。 它僅將*布爾表達式*視為返回`TRUE`或`FALSE`的條件。 > > **例如**`if(x = 1)`不允許,而`if(1 == 1)`被接受,因為它是布爾表達式,并將返回`true`。 #### `if-else if`語句語法 ```java if (1==2) System.out.println("Hello! This will not get printed"); else if(1==1) System.out.println("Hello! This will get printed"); else System.out.println("This will get executed when Above conditio is FALSE"); ``` ```java if (Boolean Expression) { Code block to get executed } else{ code block to get executed when above condition is false } ``` Java 中`If Else If`語句的示例代碼 ```java public class if_condition { public static void main(String[] args) { String string = "Hello"; if ("HI".equals(string)) { System.out.println("String has the Value Hi"); } else if ("Hello".equals(string)) { System.out.println("String is not Hi"); } string = "NotHello"; if ("Hello".equals(string)) { System.out.println("String has the Value Hello"); } else if ("Hi".equalsIgnoreCase(string)) { System.out.println("String is not Hi"); } else { System.out.println("String is neither Hello nor Hi"); } } } ``` 當您運行上述代碼時,它將打印。 ```java String is not Hi String is neither Hello nor Hi ``` * * * ## 循環語句的類型 * `for`循環 * `While`循環 * `do–While`循環 * * * ## 流控制語句的類型 * `return`語句 * `continue`語句 * `break`語句
                  <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>

                              哎呀哎呀视频在线观看