//宣告
def printSomething(): Unit = {println("Something")}
//呼叫(兩者皆可)
printSomething()
printSomething
/*----------------------------------------------------------------*/
//第二種宣告(無小括號)
def printSomething: Unit = {println("Something")}
//呼叫
printSomething() //錯誤!
printSomethingdef getMax(x: Int, y: Int) =
{
if(x > y)
x
y
}
def printSomething(): Unit = {println("Something")}void printSomething() {System.out.println("Something");}def getMax(x: Int, y: Int): Int =
{
if(x > y)
x
y
}int getMax(int x, int y)
{
if(x > y)
return x;
return y;
}def 函式名稱(參數): 回傳型態 = {程式碼} //有加等號才會回傳數值