Correct code order

Report a typo

We wrote a function checkType for object type checking. The checkType function takes an Any type argument obj and checks its type using the is and !is operators. If the obj is a String, it prints that it is a string. If the obj is not an Int, it prints that it is not an integer. If the obj is an Int, it prints that it is an integer. Arrange the code elements in the correct order provided we use the following code to call the function:

fun main() {
    checkType("Hello, World!") // prints "Hello, World! is a String"
    checkType(123) // prints "123 is an Integer"
    checkType(12.34) // prints "12.34 is not an Integer"
}
Reorder lines using drag or arrows. Adjust indentation with left buttons
                fun checkType(obj: Any) {
              
                }
              
                println("$obj is not an Integer")
              
                println("$obj is a String")
              
                } else if (obj !is Int) {
              
                if (obj is String) {
              
                } else {
              
                }
              
                println("$obj is an Integer")
              
___

Create a free account to access the full topic