Here is an example of a simple Kotlin function that takes two integer parameters and returns their sum:

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

To call this function and print the result:

val result = addNumbers(5, 7)
println('The sum is: $result')

Output: The sum is: 12

Kotlin Function Example: Adding Two Integers

原文地址: https://www.cveoy.top/t/topic/osFQ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录