视频下载地址:http://yunpan.cn/cmLjneNpDDH2Q 访问密码 e059
大数据微信公众账号:DT_Spark
Scala函数定义: 关键字def
def dowhile(){
var line =""
do {
line = readLine()
println("Read:"+line)
}while(line !="")
}
调用:
object HelloScala{
def main(args: Array[String]) {
dowhile
}
}
流程控制: if else ?
def main(args: Array[String]) {
//如果参数不为空,输出参数,注意这里不要写成args了
val file = if(!args.isEmpty) args(0) else "scala.txt"
println(file)
}
for 循环?
val files = (new java.io.File(".")).listFiles()
for(file <- files){
println(file)
}
异常处理:
val n = 99
try{
val half = if(n % 2 ==0) println(n/2) else throw
new RuntimeException("N must be event")
}catch{
//异常匹配
case e:Exception => println("The exception is :"+e.getMessage)
}finally{
}
so easy…