kotlin function
snippet in kotlin

kotlin function

user9680

fun sum(a: Int, b: Int): Int {
 return a + b
}

function kotlin

user5962

// Declare a function in Kotlin
fun happyBirthday(name: String, age: Int): String {
    return "Happy ${age}th birthday, $name!"
}
// Call function
val greeting = happyBirthday("Anne", 32)

how to write a function in kotlin

user2987

// Use 'fun' keyword to declare function
// 'num' is the parameter and is of type Int
// The ':Int' indicates the return type
fun square(num: Int):Int {
    return num * num
}