Game of Thrones alliances

Report a typo

Imagine that you are George Martin and you have a list of book characters. You want to do the following things: print this list, add one additional character to it, and print the extended list on the next line (It will help you to check different alliances). And yeah, you are also lazy enough, so you are going to do it with a chain of scope functions and methods.

Write a piece of code that prints a list of characters, adds a new character to the list from standard input, and prints the updated list. Try to do it with one chain of scope functions and methods.

Sample Input 1:

Theon Greyjoy

Sample Output 1:

Old heroes list: John Snow, Daenerys Targaryen
New heroes list: John Snow, Daenerys Targaryen, Theon Greyjoy
Write a program in Kotlin
fun main() {
val heroesList = mutableListOf("John Snow", "Daenerys Targaryen")
println("Old heroes list: ${heroesList.joinToString()}")

heroesList // Write here a chain of scope functions and MutableList methods
}
___

Create a free account to access the full topic