2019年5月21日 星期二

Kotlin學習筆記(15) 條件表達式

Kotlin學習筆記(15) 條件表達式

fun maxOf(a: Int, b: Int): Int {
    if (a > b) {
        return a
    } else {
        return b
    }
}

fun minOf(a: Int, b: Int) = if (a < b) a else b

fun main() {
    println("max of 0 and 42 is ${maxOf(0, 42)}")
    println("min of 10 and 42 is ${minOf(10, 42)}")
}

輸出畫面
max of 0 and 42 is 42 min of 10 and 42 is 10

沒有留言:

張貼留言

2026 作業1 MQTT基本觀念

 2026 作業1MQTT基本觀念 作業  參考下面網址 https://alex9ufoexploer.blogspot.com/2025/02/1-mqtt-relay-dht22-mqtt-box-pc-mymqtt.html https://alex9ufoexploer...