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.
Type system
Handling nullable types and null safety in a string program
Report a typo
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!")
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.