应用场景
当本地部署搭建完Scala开发环境后,那么就可以利用IDE开发工具进行Scala语言编程,编写一些工具等等,这里写一些简单的语法涉及,来熟悉下Scala。
运行代码
package epoint.com.cn.test001
object test001 {
def main(args: Array[String]) {
val msg = "hello world"
val greetStrings = Array("i", "like", "scala")
println(msg)
println(max(5, 6))
greet()
printargs(greetStrings)
val oneTwo = List(1, 2)
val threeFour = List(3, 4)
val oneTwoThreeFour = oneTwo ::: threeFour
println(oneTwo + " and " + threeFour + " were not mutated.")
println("Thus, " + oneTwoThreeFour + " is a new list")
val pair = (99, "Luftballons")
println(pair._1)
println(pair._2)
var jetSet = Set("Boeing", "Airbus")
jetSet += "Lear"
println(jetSet.contains("Boeing"))
val romanNumeral = Map(1 -> "I", 2 -> "II",
3 -> "III", 4 -> "IV", 5 -> "V")
println(romanNumeral(4))
}
def max(x: Int, y: Int): Int = {
if (x > y) x
else
y
}
def greet() = println("xubin nihao")
def printargs(args: Array[String]) {
var i = 0
while (i < args.length) {
println(args(i))
i += 1
}
}
}
输出打印:
hello world
6
xubin nihao
i
like
scala
List(1, 2) and List(3, 4) were not mutated.
Thus, List(1, 2, 3, 4) is a new list
99
Luftballons
true
IV