使用IntelliJ内部控制台的Kotlin readLine()函数出现问题 [英] Problem with Kotlin readLine() function using IntelliJ internal console

查看:76
本文介绍了使用IntelliJ内部控制台的Kotlin readLine()函数出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试从用户那里读取一些值时,我得到奇怪的行为.

When I try to read some value from a user, I get strange behavior.

例如,如果我有一个简单程序:

For example, if I have one simple program:

fun main() {
    print("insert value: ")
    val tmp = readLine()
    println("value = $tmp")
}

我希望程序的下一个行为:

I would expect the next behavior of the program:

insert value: 1
value = 1

但是我得到下一个行为:

But I get the next behavior:

insert value: 1
1
value = 1

所以我希望插入值1,按Enter,程序将输出value = 1.但是,相反,我必须输入值1,按Enter,输入值1,按Enter,然后得到所需的输出.

So I would expect to insert the value 1, hit Enter, and the program would output value = 1. But instead of this, I have to input the value 1, hit Enter, input the value 1, hit Enter, and then I get the desired output.

是否可以在外部控制台而不是IntelliJ内部控制台中运行Kotlin程序?因为我将IntelliJ更新为最新版本,并假设新版本可能存在问题?

Is there any option to run the Kotlin program in an external console instead of the IntelliJ internal console? Because I updated IntelliJ to the latest version and assume that maybe there is a problem with the new version?

推荐答案

在您的Kotlin REPL

   fun main() {
        print("insert value: ")
        val tmp = readLine()
        println("value = $tmp")
    }
    main()

然后要执行,请按Ctrl + Enter

Then to execute you press Ctrl+Enter

您得到:

insert value: 

然后插入值1并再按一次Ctrl + Enter来执行.

then insert the value 1 and press Ctrl+Enter one more time to execute.

,输出为:

insert value: 1
value = 1

这篇关于使用IntelliJ内部控制台的Kotlin readLine()函数出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆