Read String form Console Input – Scala

If you are developing a console application with Scala, you may need to read input from the user.

In this tutorial, we will learn how to read a line from the console as input from a user.

To read a line from console input, we use the method

Example 1 – Read String from Console as Input

In this example, we shall read a string from console and print it to the console.


object ReadInputExample {
  def main(args: Array[String]) {
    val name ="Enter your name: ")
    println("Hello "+name)


Enter your name: Arjun
Hello Arjun