0

Kotlin 23.2 task.

Everything will be useful, especially code. Thanks

26th Jul 2021, 6:36 AM
Владислав
Владислав - avatar
5 ответов
+ 3
//maybe you missed an [0] somewhere else fun main(args: Array<String>) { var letter = readLine()!![0] val names = arrayOf("John", "David", "Amy", "James", "Amanda", "Dave", "Bob", "Billy", "Bobby", "Diana", "Lenny", "Gina") val res = names.filter({it[0] == letter}) for(i in res){ println(i) } }
26th Jul 2021, 8:25 AM
Simba
Simba - avatar
+ 1
val res = names.filter({it[0]==letter}) Also, you need to output each of the resulting names on a separate line for(i in res){ println(i) }
26th Jul 2021, 8:03 AM
Simba
Simba - avatar
+ 1
Need to be more attentive, forgot to put 'it' in brackets. Thx a lot 🤝
26th Jul 2021, 8:36 AM
Владислав
Владислав - avatar
0
/* You are given an array of names and need to output only the names that start with the given letter. The letter should be taken from user input. Each of the resulting names should be output on a separate line. */ fun main(args: Array<String>) { var letter = readLine()!![0] val names = arrayOf("John", "David", "Amy", "James", "Amanda", "Dave", "Bob", "Billy", "Bobby", "Diana", "Lenny", "Gina") val res = arr.filter{it==letter} println(res) } I know, that using "==" isn't right, but I have no idea how to solve it. Need some advice or explanation please
26th Jul 2021, 7:36 AM
Владислав
Владислав - avatar
0
Same result. "Operator '==' cannot be applied to 'Char' and 'String'
26th Jul 2021, 8:22 AM
Владислав
Владислав - avatar