Is it possible for resolving this as well: | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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) }

9th Apr 2021, 5:30 AM
Fardina Kabir
Fardina Kabir - avatar
3 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
9th Apr 2021, 8:42 AM
Fardina Kabir
Fardina Kabir - avatar
+ 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
9th Apr 2021, 8:38 AM
Fardina Kabir
Fardina Kabir - avatar
+ 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
9th Apr 2021, 8:45 AM
Fardina Kabir
Fardina Kabir - avatar