Skip to content

Latest commit

 

History

History
executable file
·
59 lines (48 loc) · 1.08 KB

scala1.md

File metadata and controls

executable file
·
59 lines (48 loc) · 1.08 KB

请勿进行商业转载,学习交流转载请注明出处

安装Scala

第一个程序 (Hello World)#

  • 编译&运行
1.scala: 
object HelloWorld { 
  def main(args: Array[String]) { 
  println("Hello, world!") 
  } 
} 

hcheng@chenghao:~/home/hcheng/scalac 1.scala 
hcheng@chenghao:~/home/hcheng/scala HelloWorld 
  • 在Scala Shell中执行
hcheng@chenghao:~/SCALA_HOME/bin/scala

scala>println("Hello, world!")
Hello, world!
scala>
  • 当作普通脚本运行
2.scala:
println("Hello, world!")

$/tmp>scala 2.scala
Hello, world!
  • 当作Shell脚本运行
file: script.sh
#!/bin/sh
exec scala "$0" "$@"
!#
object HelloWorld {
  def main(args: Array[String]) {
    println("Hello, world! " + args.toList)
  }
}
HelloWorld.main(args)
$/tmp>chmod +x script.sh
$/tmp>./script.sh
Hello, world!