Home

Reading from the terminal

Reading from the terminal

To read input from the terminal, there are a number of readXXX-methods. The methods are part of the scala.io.StdIn object, so you have to import them before you can use them, for instance like this:

import scala.io.StdIn.{readLine,readInt}
The most important functions are For instance:
import scala.io.StdIn.{readInt,readBoolean}

print("How many beer? ")
val n = readInt()
printf("You ordered %d beer\n", n)
print("Are you sure? ")
if (readBoolean())
  printf("Serving %d beer\n", n)