scala实例练习1
2018-03-28 本文已影响16人
小呀小芒果
scala script脚本Demo.scala编译运行方式
object Demo {
def main(args: Array[String]) {
var str1 = "Dot saw I was ";
var str2 = "Tod";
println("Dot " + str1 + str2);
}
}
E:\ideaIC\bigdata\src>scalac Demo.scala
E:\ideaIC\bigdata\src>dir
2018/03/27 23:29 927 Demo$.class
2018/03/27 23:29 607 Demo.class
2018/03/27 23:24 152 Demo.scala
2018/03/27 23:09 190 Demo_class.scala
E:\ideaIC\bigdata\src>scala Demo
Dot Dot saw I was Tod
字符串插值器
字符串处理时可以直接引用变量或者表达式,省去了在拼接处理。(Scala-2.10及更高版本)
object Demo {
def main(args: Array[String]) {
val name = "James"
println(s"Hello, $name")
println(s"1 + 1 = ${1 + 1}")
}
}