Out of bounds!

Report a typo

Take a look at the program that reads a string and a number N and outputs the Nth element of the string.

This program may throw StringIndexOutOfBoundsException. Fix it to avoid the exception.
In the case when the exception might happen, your updated program should output: Out of bounds!

Write a program in Kotlin
import java.util.*

fun main() {
val string = readln()
val index = readln().toInt()
println(string[index])
}
___

Create a free account to access the full topic