+ 2
Is it possible for resolving this as well:
Is it possible for resolving this as well: First Letters Kotlin pro You are given code that should iterate through an array and output the first letters of each element. However, the code has errors. Fix the code to result in the expected output fun main(args: Array<String>) { var arr = arrayOf("James", "Amy", "Sam", "Olie", "Bob") val res = "" arr.forEach() { str -> res += item-1 } println(res) }
5 Answers
+ 3
Coder Kitten
fun main(args: Array<String>) {
val arr = arrayOf("James", "Amy", "Sam", "Olie", "Bob")
arr.forEach() {
println(it[0])
}
}
This one of your also worked
+ 1
fun main(args: Array<String>) {
var arr = arrayOf("James", "Amy", "Sam", "Olie", "Bob")
var res = StringBuilder()
arr.forEach() {
res.append(it[0])
}
println(res.toString())
}
This one of your worked. Passed the test case. Thank you a lot
+ 1
fun main(args: Array<String>) {
val arr = arrayOf("James", "Amy", "Sam", "Olie", "Bob")
var res = ""
arr.forEach() {
res += it[0]
}
println(res)
}
Coder Kitten this one also worked. All of your solutions worked. Thanks a lot. I understood the concept