<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智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # Kotlin 程序:生成乘法表 > 原文: [https://www.programiz.com/kotlin-programming/examples/multiplication-table](https://www.programiz.com/kotlin-programming/examples/multiplication-table) #### 在此程序中,您將學習生成給定數字的乘法表。 這是通過在 Kotlin 中使用`for`和`while`循環來完成的。 您還將學習使用范圍來解決問題。 ## 示例 1:使用`for`循環生成乘法表 ```kt fun main(args: Array<String>) { val num = 5 for (i in 1..10) { val product = num * i println("$num * $i = $product") } } ``` 運行該程序時,輸出為: ```kt 5 * 1 = 5 5 * 2 = 10 5 * 3 = 15 5 * 4 = 20 5 * 5 = 25 5 * 6 = 30 5 * 7 = 35 5 * 8 = 40 5 * 9 = 45 5 * 10 = 50 ``` 與 Java 不同,在上述程序中,我們使用了`range`和`in`運算符來循環從 1 到 10 的數字。 以下是等效的 Java 代碼:[生成乘法表的 Java 程序](/java-programming/examples/multiplication-table)。 * * * 還可以使用 Kotlin 中的`while`循環來生成相同的乘法表。 ## 示例 2:使用`while`循環生成乘法表 ```kt fun main(args: Array<String>) { val num = 9 var i = 1 while (i <= 10) { val product = num * i println("$num * $i = $product") i++ } } ``` 運行該程序時,輸出為: ```kt 9 * 1 = 9 9 * 2 = 18 9 * 3 = 27 9 * 4 = 36 9 * 5 = 45 9 * 6 = 54 9 * 7 = 63 9 * 8 = 72 9 * 9 = 81 9 * 10 = 90 ``` 在上面的程序中,與`for`循環不同,我們必須在循環體內增加`i`的值。 盡管兩個程序在技術上都是正確的,但在這種情況下最好使用`for`循環。 這是因為已知迭代次數(從 1 到 10)。
                  <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>

                              哎呀哎呀视频在线观看