How to take input from a user in Scala?
I want to take input from the user. Can you please tell me how to ask for user input as a string in Scala?
In Scala 2.11 use
scala.io.StdIn.readLine()
instead of the deprecated Console.readLine
.
From the Scala maling list (formatting and links were updated):
Short answer:
readInt
Long answer:
If you want to read from the terminal, check out
Console.scala
. You can use these functions like so:Console.readInt
Also, for your convenience,
Predef.scala
automatically defines some shortcuts to functions inConsole
. Since stuff inPredef
is always and everywhere imported automatically, you can use them like so:readInt