object Program {
def lengthOfLastWord(str: String): Int = {
val words = str.split(" ").toList
words.last.length
}
def main(args: Array[String]): Unit = {
val str = "java c javascript golang"
println(s"The length of the last word is: ${lengthOfLastWord(str)}")
}
}
/*
run:
The length of the last word is: 6
*/