如何编写 hello world
目标
我想用 Scala 编写 hello world 程序并运行它。
步骤
-
新建一个目录,例如
hello_scala/ -
在
hello_scala/下创建名为project/的目录,并创建project/build.properties,内容为sbt.version=2.0.0-RC10 -
在
hello_scala/下创建build.sbt:scalaVersion := "3.8.2" -
在
hello_scala/下创建Hello.scala:@main def main(args: String*): Unit = println(s"Hello ${args.mkString}") -
在终端中进入
hello_scala/并运行sbt:$ sbt -
出现提示符后,输入
run:sbt:hello_scala> run -
输入
exit退出 sbt shell:sbt:hello_scala> exit
其他方式
若您赶时间,可在空目录中运行 sbt init,并选择第一个模板。