<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、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # Kotlin 程序:檢查數字是正數還是負數 > 原文: [https://www.programiz.com/kotlin-programming/examples/positive-negative](https://www.programiz.com/kotlin-programming/examples/positive-negative) #### 在此程序中,您將學習檢查給定的數字是正數還是負數。 這可以通過在 Kotlin 中使用`if-else`語句或`when`表達式來完成。 要檢查數字是正數還是負數,請將其與 0 進行比較。 * 如果數字大于零,則為正數。 * 如果數字小于零,則為負數。 * 如果數字等于零,則為零。 ## 示例 1:使用`if else`語句檢查數字是正數還是負數 ```kt fun main(args: Array<String>) { val number = 12.3 if (number < 0.0) println("$number is a negative number.") else if (number > 0.0) println("$number is a positive number.") else println("$number is 0.") } ``` 運行該程序時,輸出為: ```kt 12.3 is a positive number. ``` 以下是等效的 Java 代碼:[用于檢查數字是正數還是負數的 Java 程序](/java-programming/examples/positive-negative)。 * * * 上述程序中的`if else`語句也可以使用`when`表達式替換。 ## 示例 2:使用`when`表達式檢查數字是正數還是負數 ```kt fun main(args: Array<String>) { val number = -12.3 when { number < 0.0 -> println("$number is a negative number.") number > 0.0 -> println("$number is a positive number.") else -> println("$number is 0.") } } ``` 運行該程序時,輸出為: ```kt -12.3 is a negative number. ```
                  <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>

                              哎呀哎呀视频在线观看