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.
StringBuffer
Is there any room?
Report a typo
Sample Input 1:
Sample Output 1:
Remaining room in the buffer: 16
Updated remaining room in the buffer: 28Write 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")
}
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.