環境: CentOS 6.3
看例子,說實話。
入門函數:
scala> def max(x: Int,y: Int): Int = {
| if (x > y) x //豎線| 是換行是自動顯示的,不是代碼本身
| else y
| }
max: (x: Int, y: Int)Int //上面代碼敲完後,這行就會自動出來
scala> max(3,6)
res3: Int = 6
scala> max(3,1)
res4: Int = 3
解析:def max (x: Int, y: Int): Int
函數定義標識符 函數名字 參數名及類型 參數名及類型 函數值返回類型
返回值爲空函數:
scala> def greet() = print("this is no result type function")
greet: ()Unit
scala> greet
this is no result type function