關於scala 函式定義 流程控制 異常處理
阿新 • • 發佈:2019-02-17
scala是基於ivm的語言,相比java而言,有些語法更加簡潔,個人感覺跟swift有點相似,不說了 直接上程式碼
package com.dt.hello
/**
* @author ly
*/
object Hello {
def main(args: Array[String]): Unit = {
println("ss");
printHello()
loopForFunction
exceptionFunction
loopWhileFunction
}
def printHello(){
println("hello")
}
def loopForFunction(){
for(i<-1 to 10)
println(i)
}
def loopWhileFunction{
var i = 0
do{
i+=1
println(i)
}
while(i<5)
}
def exceptionFunction(){
try{
throw new RuntimeException("test exception")
}
catch{
case e:Exception=>println("Exception:"+e.getMessage)
}
finally{
}
}
}
資訊來源於 DT大資料夢工廠微信公眾賬號:DT_Spark