What does this print?
fun calc(
a: Int, b: Int, op: String
): Int {
return if (op == "+")
a + b else a - b
}
fun main() {
println(calc(
b = 5, a = 3, op = "+"
))
println(calc(
op = "?", a = 3, b = 5
))
}
Try it in the online Kotlin Playground →
[spoiler title="Solution"]
Answer:
8 -2
Explanation:
Named arguments allow reordering and clarity.
[/spoiler]