I want to take input from the user. Can you please tell me how to ask for user input as a string in Scala?
Read String form Console Input – Scala To read a line from console input, we use the method scala. io. StdIn. readLine() .
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.
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.
In Scala 2.11 use
scala.io.StdIn.readLine()
instead of the deprecated Console.readLine
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With