Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Console Char input can be read in Kotlin using the following code:

val input = readLine()
val charInput = input?.get(0)

In this code, readLine() is used to read the input from the console. The input is then assigned to the variable input. Since readLine() returns a String, the first character of the string is extracted using the get() method and assigned to the variable charInput.

It is important to note that the get() method returns a nullable type, so a safe call (?.) is used to ensure that the code does not throw an exception if the input is null.