kotlin functions code example
Example 1: kotlin function
fun sum(a: Int, b: Int): Int {
return a + b
}
Example 2: function kotlin
fun happyBirthday(name: String, age: Int): String {
return "Happy ${age}th birthday, $name!"
}
val greeting = happyBirthday("Anne", 32)
Example 3: return type in kotlin function
fun sum(a: Int, b: Int): Int {
return a + b
}
Example 4: make function kotlin
fun main() {
println("This is a function")
}
Example 5: how to write a function in kotlin
fun square(num: Int):Int {
return num * num
}