为什么 readLine() 在我的 Kotlin 代码中不起作用?
我有这段代码
fun main() {
var input = "1.785 + 9755.44"
val inputarr = input.split(" ")
var output = inputarr[0].toDouble() + inputarr[2].toDouble()
println(output)
var a: String? = readLine()
println(a)
}
,当我运行它时,它会执行到 print(output)
,但之后它就会停止,甚至不会停止运行。发生这种情况时,我被迫关闭 IDE 并重新启动。
我无法向 a
输入任何内容。
我一开始以为我的设置可能有问题,但是当我在 https://play.kotlinlang 上尝试时。 org/,我遇到了不同的问题。
我没有在 println(output)
部分后显示空白,而是在其后显示 null
。
知道问题出在哪里吗?
I have this block of code
fun main() {
var input = "1.785 + 9755.44"
val inputarr = input.split(" ")
var output = inputarr[0].toDouble() + inputarr[2].toDouble()
println(output)
var a: String? = readLine()
println(a)
}
When I run it, it executes up to print(output)
, but after that it just stops and doesn't even stop the running. I am forced to close the IDE and start again when this happens.
There is no way for me to input anything into a
.
I thought at first that maybe something was wrong with my setup, but when I tried it on https://play.kotlinlang.org/, I got the different problem.
Instead of showing blank after the println(output)
part, I got null
after it.
Any idea what the problem could be?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于 doc,
readLine ()
返回:所以我想这取决于你的IDE如何管理输入流。我用 IntelliJ IDEA 尝试了你的代码,一切正常。
尝试检查您的 IDE 设置以更改其行为或尝试 IntelliJ IDEA。
Due to doc,
readLine()
returns:So I guess it depends on your IDE to how to manage the input stream. I tried your code with IntelliJ IDEA and everything was OK.
Try checking your IDE settings to change its behavior or try IntelliJ IDEA.