Kotlin: using the when expression
Example:
val x = 5
The "when" expression replaces the switch statement in Kotlin.
Solution:
when (x) {
1 -> print("x == 1")
5 -> print("x == 5")
else -> print("x is neither 1 nor 5")
}
Example: Solution:Kotlin: using the when expression
The "when" expression replaces the switch statement in Kotlin.
val x = 5
when (x) {
1 -> print("x == 1")
5 -> print("x == 5")
else -> print("x is neither 1 nor 5")
}