Is there any room?

Report a typo

We have a StringBuffer object called buffer. Write a function calculateRoom that returns an Int of how many characters we can append to buffer without increasing its capacity.

Sample Input 1:

Sample Output 1:

Remaining room in the buffer: 16
Updated remaining room in the buffer: 28
Write a program in Kotlin
fun calculateRoom(...) { // Do not change the function's name
}

// Do not change the code below
fun main() {
val buffer = StringBuffer("Hello, Kotlin!")
val remainingRoom = calculateRoom(buffer)
println("Remaining room in the buffer: $remainingRoom")

buffer.append(" This is Hyperskill!")
val newRemainingRoom = calculateRoom(buffer)
println("Updated remaining room in the buffer: $newRemainingRoom")
}
___

Create a free account to access the full topic