0
Kotlin 23.2 task.
Everything will be useful, especially code. Thanks
5 Answers
+ 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)
}
}
+ 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)
}
+ 1
Need to be more attentive, forgot to put 'it' in brackets.
Thx a lot š¤
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
0
Same result.
"Operator '==' cannot be applied to 'Char' and 'String'