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")
}



沒有留言:

張貼留言

2024產專班 作業2 (純模擬)

2024產專班 作業2  (純模擬) 1) LED ON,OFF,TIMER,FLASH 模擬 (switch 控制) 2)RFID卡號模擬 (buttom  模擬RFID UID(不從ESP32) Node-Red 程式 [{"id":"d8886...