'Kotlin readln() does not work as intended

If I assign values from readln() successively, they do not work properly; the second variable is an empty line.

fun main() {
  val first = readln()
  val second = readln()
  println(first)
  println(second) 
}

Does the second variable reads in some empty string or changeLine thing? If I switch the order of line 3 and line 4, everything just works fine.

fun main() {
  val first = readln()
  println(first)
  val second = readln()
  println(second)
}

Just wondering what happened in the first code?

edit : I tried this in Intellij community under Win11 and Ubuntu in VMware. Here is the picture: console debug I ran the code by left-clicking the green triangle.

edit: the first code worked fine on my old laptop, but after I updated my Intellij to the latest version, the first code broke as well.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source