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")
//...
}
}
Source: stackoverflow.com
Related Query
- Type checking on user input Scala Spark
- Input type must be string type but got ArrayType(StringType,true) error in Spark using Scala
- Type mismatch error on checking presence of element in a Set in Spark Scala API
- Filter condition based on user input Spark Scala
- Scala slick query comparison of a custom user type (enumeration) gives error
- prompt for user input when running scala program with sbt
- What is the Scala type mapping for all Spark SQL DataType
- Better type checking on match in Scala
- Checking for varargs type ascription in Scala macros
- How to echo user input in Scala REPL?
- VectorAssembler does not support the StringType type scala spark convert
- Dropping columns by data type in Scala Spark
- Unsupported literal type class in Apache Spark in scala
- Get elements of type structure of row by name in SPARK SCALA
- Checking Function Type in Scala
- How do I handle unicode user input in Scala safely (esp XML entities)
- Input validation with the scala type system
- Scala compiler failed to infer type inside Spark lambda function
- How to see the type of a scala variable? For instance a Spark PairRDD
- Checking scala types at runtime and type erasure
- How to read from textfile(String type data) map and load data into parquet format(multiple columns with different datatype) in Spark scala dynamically
- Is it possible for Scala to offer type checking inside scripts?
- Checking null value in Scala for Java data type
- Scala type mismatch error even after checking type with isInstanceOf
- Scala dynamic return type based on input type
- Scala : Type Nothing with User defined classes
- Type of user defined objects in Scala
- Scala generic type usage in Apache Spark Dataset creation
- Scala type checking compilation error
- Getting error like need struct type but got string in spark scala for simple struct type
More Query from same tag
- Implicit conversion in monadic for comprehension in Scala
- Scala Spark, array with incremental new column
- How to check if some type confirms to generic type bounds in Scala macros?
- Replace a value in a row with a value in another row in Spark dataframe
- How to integrate subcut dependent modules?
- Scala reflection - Java enum generic object
- Scala Unable to pimp NaturalTransformation in scalaz or cats
- Why does IntelliJ IDEA say "Cannot resolve symbol spark" for spark.sparkContext.textFile?
- Future and latency: How to prioritize the execution of some Futures over the others
- How to disable akka.dispatch.BatchingExecutor?
- Cannot reuse a function for quill SQL filtering
- How can I read this avro file using spark & scala?
- How to log custom flatMap function in Flink (scala) on Kubernetes?
- Is there an easy way to chain java setters that are void instead of return this
- how to downgrade proguard version in android studio gradle?
- scala quirky in this while loop code
- Why do scala REPL and Ammonite behave differently in this point and which behaviour is correct?
- How to integrate Play Framework Application Scala with Angularjs
- How can I directly test the methods of MyUserService for securesocial plugin for Play Framework
- How do you Map a Cucumber DataTable to Scala?
- Append values from one column to another JSON column in the same dataframe
- "Constructor cannot be instantiated to expected type" when defining streams in Scala
- Extending a trait and types
- Error while reading an Excel file using Spark Scala with filename as a parameter
- Using Scala Actors to create sth like a Pipeline
- when do I need to add member definitions to my class in scala?
- Scala function not passed by name with curly brackets (braces)
- Mocking database with Slick in ScalaTest + Mockito and testing UPDATE
- How to create a BufferedImage from raw data
- Merge multiple (csv) zip file content to single file zipped