We need to create function named as nullable which will accept nullable string as a parameter. Return length of the string , if NULL then -1… task as per it written code
import java.io.*
import java.math.*
import java.security.*
import java.text.*
import java.util.*
import java.util.concurrent.*
import java.util.function.*
import java.util.regex.*
import java.util.stream.*
import kotlin.collections.*
import kotlin.comparisons.*
import kotlin.io.*
import kotlin.jvm.*
import kotlin.jvm.functions.*
import kotlin.jvm.internal.*
import kotlin.ranges.*
import kotlin.sequences.*
import kotlin.text.*
--- Editable code as ---
fun nullable(s1: String?): Unit{
var b: String? = s1
b=null
val l = b?.length ?: -1
print(l)
return(l)
}
--- End ---
fun main(args: Array<String>) {
val str = readLine()!!
var result=-100
if(str=="null"){
result = nullable(null)
}else
result = nullable(str)
println(result)
}
We now getting error as -
Solution.kt:37:8: error: type mismatch: inferred type is Int but Unit was expected
return(l)
^
Solution.kt:44:19: error: type mismatch: inferred type is Unit but Int was expected
result = nullable(null)
^
Solution.kt:46:18: error: type mismatch: inferred type is Unit but Int was expected
result = nullable(str)