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

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                # Kotlin 程序:檢查數字是否為回文 > 原文: [https://www.programiz.com/kotlin-programming/examples/palindrome-number](https://www.programiz.com/kotlin-programming/examples/palindrome-number) #### 在此程序中,您將學習檢查 Kotlin 中的數字是否為回文數。 這是通過使用 while 循環完成的。 ## 示例:回文檢查程序 ```kt fun main(args: Array<String>) { var num = 121 var reversedInteger = 0 var remainder: Int val originalInteger: Int originalInteger = num // reversed integer is stored in variable while (num != 0) { remainder = num % 10 reversedInteger = reversedInteger * 10 + remainder num /= 10 } // palindrome if orignalInteger and reversedInteger are equal if (originalInteger == reversedInteger) println("$originalInteger is a palindrome.") else println("$originalInteger is not a palindrome.") } ``` 運行該程序時,輸出為: ```kt 121 is a palindrome. ``` **注意**:可以將`num`的值更改為 11221,并且在運行程序時,輸出為: ```kt 11221 is not a palindrome. ``` 以下是等效的 Java 代碼:[用于檢查回文數的 Java 程序](/java-programming/examples/palindrome-number "Java Program to Check Whether a Number is Palindrome or Not") 在這個程序中 * 首先,給定數字(`num`)的值存儲在另一個整數變量`originalInteger`中。 這是因為,我們需要在最后比較反向編號和原始編號的值。 * 然后,使用`while`循環循環遍歷`num`,直到等于 0。 * 在每次迭代中,`num`的最后一位存儲在`remainder`中。 * 然后,將`remainder`添加到`reversedInteger`,以便將其添加到下一個位置值(乘以 10)。 * 然后,除以 10 后,從`num`中刪除最后一位數字。 * 最后,比較`reversedInteger`和`originalInteger`。 如果相等,則為回文數。 如果不是,則不是。 以下是執行的步驟: 回文執行步驟 | `num` | `num != 0` | `remainder` | `reversedInteger` | | --- | --- | --- | --- | | 121 | `true` | 1 | `0 * 10 + 1 = 1` | | 12 | `true` | 2 | `1 * 10 + 2 = 12` | | 1 | `true` | 1 | `12 * 10 + 1 = 121` | | 0 | `false` | - | 121 |
                  <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>

                              哎呀哎呀视频在线观看