Bink
Bink

Reputation: 2181

readLine and try.kotlinlang.org

Learning a little Kotlin and using try.kotlinlang.org before installing the full IDE. I tried the following code, but there doesn’t appear to be a prompt for me enter text:

fun main(args: Array<String>) {
  val txt = readLine()
  if (txt != null) println("$txt")
}

There are no errors. What am I missing? Is this a limitation of try.kotlinlang.org?

Thank you.

Upvotes: 2

Views: 721

Answers (2)

user8959091
user8959091

Reputation:

Just try this:

fun main(args: Array<String>) {
    print("enter text:")
    val txt = readLine()
    if (txt != null) println("$txt")
}

position the cursor after the prompt,type anything you want and press Enter.

Upvotes: 0

David
David

Reputation: 286

I don't think the output console can take keyboard input. If you use:

fun main(args: Array<String>) {
  val txt = args[0]
  println("$txt")
}

and give it a program argument of "Bob", it will print that out.

Upvotes: 3

Related Questions