a block of code
{exp1;exp2}
{
exp1
exp2
}
A code block is also an expression whose final evaluation is the value of the last expression.
two function
def functionName(param:ParamType):ReturnType={
//function body:expressions
}
Three examples
object func_examples {
def hello(name:String):String={
s"Hello,${name}"
}//> hello: (name: String)String
hello("cakin24")//> res0: String = Hello,cakin24
def hello2(name:String)={
s"Hello,${name}"
}//> hello2: (name: String)String
hello("cakin24")//> res1: String = Hello,cakin24
def Add(x:Int,y:Int)=x+y //> Add: (x: Int, y: Int)Int
Add(1,2)//> res2: Int = 3
}