2019年5月21日 星期二

Kotlin學習筆記(22) Keyboard Input 鍵盤輸入資料 readLine ()

Kotlin學習筆記(22)  Keyboard Input 鍵盤輸入資料 readLine ()

使用  https://rextester.com/l/kotlin_online_compiler   online kotlin

/*
範例輸入
world
C++
mary

範例輸出
hello, world
hello, C++
hello, mary
*/

fun main (argument: Array <String>) {
//coding180.com
    print ("Enter first value:")
    val value1 = readLine () !!. toInt ()
    print ("Enter second value:")
    val value2 = readLine () !!. toInt ()
    val sum = value1 + value2
    println ("The sum of $value1 and $value2 is $sum")
    val product = value1 * value2
    println ("The product of $value1 and $value2 is $product")
}

輸入資料
12
23

輸出資料
Enter first value:Enter second value:The sum of 12 and 23 is 35
The product of 12 and 23 is 276


使用  https://www.jdoodle.com/compile-kotlin-online 

//Program created for https://beginnersbook.com

fun main(args: Array<String>) {
   
    print("Write anything here: ")
    val enteredString = readLine()
    println("You have entered this: $enteredString")
   
    print("Write any number: ")

    val number = Integer.valueOf(readLine())
    println("The entered number is: $number")
}



沒有留言:

張貼留言

ESP32 微控制器 採集的環境數據,經由 MQTT 協定 轉換並寫入工業標準的 Modbus 暫存器 中

  一個典型的 IoT(物聯網)與工業自動化系統整合(SCADA/機台連線) 的架構圖。它透過 Node-RED 作為核心資料網關,將前端 ESP32 微控制器 採集的環境數據,經由 MQTT 協定 轉換並寫入工業標準的 Modbus 暫存器 中。 1. 各模組功能拆解...