Back to questions
JuniorTheoryCommon
What does the program print (lines separated by spaces)?
fun main() {
val s = "Kotlin"
println(s.substring(1, 3))
println(s.indexOf('t'))
}ot 2
- Expecting
otl 2: thinkingsubstring(1, 3)includes index3. The end is left out, so it returns the letters at indexes1and2,ot. - Expecting
ot 3: counting letters from1. Indexes start at0, soindexOf('t')returns2for the third letter.
- What does
s.indexOf('z')return? - What does
s.substring(3)return?