1 Answers
We can write a switch statement in two methods. The code of switch statement for Kotlin is below.
fun main(args:Array<String>){
val num : Int = 2
when(num)
{
1 -> println(“It is one”)
2 -> println(“It is two”)
3 -> println(“It is three”)
4 -> println(“It is four”)
else -> println(“Give the proper input”)
}
val num1 : Int = 2
val str = when(num1)
{
1 -> “It is one”
2 -> “It is two”
3 -> “It is three”
4 -> “It is four”
else -> “Give the proper input”
}
println(“Is $str”)
}