The command line interpreter of scala shows:
scala> Console.readInt
warning: there was one deprecation warning; re-run with -deprecation for details
res0: Int = 65
Is Console.readInt
really deprecated? If yes, what is the correct way of taking input?
I am using Scala version 2.11.7 on OS X 10.10.5.
In Scala 2.11 you can use
scala.io.StdIn.readInt()
or
scala.io.StdIn.readLine().toInt
As suggested by the REPL, run scala -deprecation
to get more info:
scala -deprecation
Welcome to Scala version 2.11.2 (OpenJDK 64-Bit Server VM, Java 1.7.0_79).
Type in expressions to have them evaluated.
Type :help for more information.
scala> Console.readInt
<console>:8: warning: method readInt in class DeprecatedConsole is deprecated: Use the method in scala.io.StdIn
Console.readInt
^
Or, you can use import to depress the warning:
import scala.io.StdIn._
val name = readLine("Your name:")
val age = readInt()
printf("Your name: %s, your age: %d\n", name, age)
Check the Scala Api
(Since version 2.11.0) Use the method in scala.io.StdIn
It also has readInt
method
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With