Handling nullable types and null safety in a string program

Report a typo

Implement a Kotlin program that initially has a nullable string. Your program should first print the length of the string if it's not null. Afterwards, set the string value to null and print 'Value is null!' if the string is found to be null upon checking its length. In this exercise, you need to consider null safety while dealing with nullable types in Kotlin. Your challenge is to reorder the lines of code provided to make this program work correctly.

Reorder lines using drag or arrows. Adjust indentation with left buttons
                fun main() {
              
                str = null
              
                var str: String? = "Hello, World"
              
                }
              
                print(str?.length)
              
                print(str?.length ?: "Value is null!")
              
___

Create a free account to access the full topic