Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to take input from a user in Scala?

Tags:

scala

I want to take input from the user. Can you please tell me how to ask for user input as a string in Scala?

like image 877
sam Avatar asked Feb 20 '11 05:02

sam


People also ask

How do you input strings in Scala?

Read String form Console Input – Scala To read a line from console input, we use the method scala. io. StdIn. readLine() .

What is Println in Scala?

The “println” command in the Scala programming language is used to print a line while introducing a new line at the end. In this way, if you want to print more than one line, each of them will be printed on a separate line.

How do I run a main method in Scala?

The @main Annotation. Scala 3 has introduced the annotation @main to allow a method to be converted into the entry point of an executable program. If we save helloWorld as a file, like HelloWorld. scala, we can run it simply by executing scala helloWorld, after compiling it with scalac.


1 Answers

In Scala 2.11 use

scala.io.StdIn.readLine() 

instead of the deprecated Console.readLine.

like image 82
elm Avatar answered Sep 20 '22 03:09

elm