Thin threads

Report a typo

Your friend wrote this code so that it should print: 200_000, but each time the code gets executed, a different output is printed, which is always less than 200_000.

Help your friend fix the code so that it will print the desired output.

Sample Input 1:

Sample Output 1:

200000
Write a program in Kotlin
import kotlin.concurrent.thread

fun addNumbers(numbers: StringBuilder) {
for (i in 0 until 100_000) numbers.append(i.toString().first())
}

fun main() {
val numbers = StringBuilder(200_000)
val thread = thread(start = false, name = "Thread 1") {
addNumbers(numbers)
}

thread.start()
addNumbers(numbers)

thread.join()

println(numbers.length)
}
___

Create a free account to access the full topic