Completing a number range checking program

Report a typo

Imagine a program written in Kotlin that checks if a given number is within certain ranges and prints out an appropriate message. We want it to print 'Number is in the range 1..3' if the number is between and including 1 and 3; 'Number is not in the range 4..10' if the number is not between and including 4 and 10; and 'Number is in the range 4..10' if the number is between and including 4 and 10. The starting code already uses the required Control Structures. The task is to fill the blanks in the provided code to make it work as intended.

Fill in the gaps with the relevant elements
fun main() {
    var number = 5
     (number) {
         1..3 -> println("Number is in the range 1..3")
        !in 4..10 -> println("Number is not in the range 4..10")
         -> println("Number is in the range 4..10")
    }
}
elseinwhen
___

Create a free account to access the full topic