Back to questions
JuniorTheoryCommon
What does the program print (lines separated by spaces)?
fun main() {
val s = "hello"
s.uppercase()
println(s)
println(s.uppercase())
}hello HELLO
- Expecting
HELLO HELLO: thinkinguppercase()changess. It returns a new string, and withoutval upper = …or aprintlnthat result is lost. - Expecting a compile error because
sis aval:valonly forbidss = …; calling a function that returns a new string is allowed.
- How would you keep the upper-case version so that
println(s)printsHELLO? - What happens when the program tries
s[0] = 'H'?