Scala functions and code blocks

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
  1. object func_examples {
  2. def hello(name:String):String={
  3. s"Hello,${name}"
  4. }//> hello: (name: String)String
  5. hello("cakin24")//> res0: String = Hello,cakin24
  6. def hello2(name:String)={
  7. s"Hello,${name}"
  8. }//> hello2: (name: String)String
  9. hello("cakin24")//> res1: String = Hello,cakin24
  10. def Add(x:Int,y:Int)=x+y //> Add: (x: Int, y: Int)Int
  11. Add(1,2)//> res2: Int = 3
  12. }

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326946702&siteId=291194637