score:1

Accepted answer

You can read the input as a string using scala.io.StdIn.readLine() then try to parse it to Int and use pattern matching to handle case for valid int and for error.

Something like this :

for (iteration <- 0 to 19) {
  var personalRate = scala.io.StdIn.readLine()

  Try(personalRate.toInt).toOption match {
    case Some(rate) => {
      println(rate)
      // your logic for int 
    }
    case _ => println("Error")
    
   //...
  }
}

Related Query

More Query from same tag