<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/print-integer](https://www.programiz.com/kotlin-programming/examples/print-integer) #### 在此程序中,您將學習如何打印用戶輸入的整數。 整數存儲在變量中,并分別使用`nextInt()`和`println()`函數打印到屏幕上。 ### 示例 1:如何打印用戶在 Kotlin 中使用掃描器輸入的整數 ```kt import java.util.Scanner fun main(args: Array<String>) { // Creates a reader instance which takes // input from standard input - keyboard val reader = Scanner(System.`in`) print("Enter a number: ") // nextInt() reads the next integer from the keyboard var integer:Int = reader.nextInt() // println() prints the following line to the output screen println("You entered: $integer") } ``` 運行該程序時,輸出為: ```kt Enter a number: 10 You entered: 10 ``` * * * 在此示例中,創建了一個`Scanner`類的對象,即`reader`,它從`keyboard`(標準輸入)獲取用戶的輸入。 然后,`nextInt()`函數讀取輸入的整數,直到遇到換行符`\n (Enter)`為止。 然后將整數保存在類型為`Int`的變量`integer`中。 最后,`println()`函數使用字符串模板將`integer`打印到標準輸出:計算機屏幕。 * * * 上面的程序與 Java 非常相似,沒有樣板類代碼。 您可以在此處找到等效的 Java 代碼:[打印整數的 Java 程序](/java-programming/examples/print-integer "How to print an Integer in Java") * * * ### 示例 2:如何在不使用掃描器的情況下打印整數 ```kt fun main(args: Array<String>) { print("Enter a number: ") // reads line from standard input - keyboard // and !! operator ensures the input is not null val stringInput = readLine()!! // converts the string input to integer var integer:Int = stringInput.toInt() // println() prints the following line to the output screen println("You entered: $integer") } ``` 運行該程序時,輸出為: ```kt Enter a number: 10 You entered: 10 ``` * * * 在上面的程序中,我們使用函數`readLine()`從鍵盤讀取一行字符串。 由于`readLine()`也可以接受空值,因此`!!`運算符確保變量`stringInput`的值不為空。 然后,使用函數`toInt()`將存儲在`stringInput`中的字符串轉換為整數值,并存儲在另一個變量`integer`中。 最后,使用`println()`將整數打印到輸出屏幕上。
                  <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>

                              哎呀哎呀视频在线观看