1、使用return def functionName ([参数列表]) : [return type] = { function body return [expr] } 2、直接把返回值写在最后:
object Test { def main(args: Array[String]) { println( "Returned Value : " + addInt(5,7) ); } def addInt( a:Int, b:Int ) : Int = { var sum:Int = 0 sum = a + b sum } }