scala入门测试

scala入门测试:
安装可以直接sudo apt-get install scala
或者在官网下载scala安装包安装。
我是通过前一种安装

1.注意事项1:

scala test.scala
scala test

这种方式行不通,会报错:

xubo@xubo:~/cloud/test$ scala ScalaTest
Exception in thread "main" java.lang.RuntimeException: Cannot figure out how to run target: ScalaTest
    at scala.sys.package$.error(package.scala:27)
    at scala.tools.nsc.GenericRunnerCommand.scala$tools$nsc$GenericRunnerCommand$$guessHowToRun(GenericRunnerCommand.scala:38)
    at scala.tools.nsc.GenericRunnerCommand$$anonfun$2.apply(GenericRunnerCommand.scala:48)
	at scala.tools.nsc.GenericRunnerCommand$$anonfun$2.apply(GenericRunnerCommand.scala:48)
    at scala.Option.getOrElse(Option.scala:108)
    at scala.tools.nsc.GenericRunnerCommand.<init>(GenericRunnerCommand.scala:48)
    at scala.tools.nsc.GenericRunnerCommand.<init>(GenericRunnerCommand.scala:17)
    at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:33)
    at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:89)
    at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
xubo@xubo:~/cloud/test$ 

直接运行:

xubo@xubo:~/cloud/test$ scala ScalaTest.scala 
hello scala

test.scala代码:

val hello="hello world"
println(hello)

ScalaTest.scala 代码:

object ScalaTest{
  def main(args:Array[String]){
   println("hello scala")
 }
}

输出结果类似。

2.scala CMD:
在终端输入scala进入命令端口:

xubo@xubo:~/cloud/scala-2.9.2$ scala
Welcome to Scala version 2.9.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_79).
Type in expressions to have them evaluated.
Type :help for more information.

scala>

循环结构:

scala> for(i <- 1 to 10 ) println("No."+i)
No.1
No.2
No.3
No.4
No.5
No.6
No.7
No.8
No.9
No.10

你可能感兴趣的:(scala,安装,测试)