readLine() only reads second input in console

与世无争的帅哥 提交于 2021-02-08 06:30:09

问题


I'm just getting started with Kotlin, so I apologize if it's a dumb problem (which I think it probably is).

I'm following this guide, but ran in an issue: the readLine function ignores my first input, and returns only the second line I insert.

fun main() {
    println("What's your name?")
    val name= readLine()
    println("Hello $name!")
}

And this is the output I'm getting (">" marks my input into the console):

What's your name?
> Paul
> John
Hello John!

I'm using IntelliJ IDEA Community 2020.2, if that makes a difference. Thanks in advance for any help!

来源:https://stackoverflow.com/questions/65100768/readline-only-reads-second-input-in-console

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!