package com.wyh.day01 object ScalaFun1 { def main(args: Array[String]): Unit = { val result = stringPan("数加") println(result) val result2 = SumData(1,2,5,6,4,7,8,7) println(result2) val result3 = Cli("master") println(result3) val result4 = digui(4) println(result4) } /** * 定义个方法 */ def stringPan(str:String): String ={ if("数加".equals(str)){ "数加" }else if("大数据".equals(str)){ "大数据" }else{ "未匹配到" } } /** * 可变参数 */ def SumData(data:Int*):Int={ var sum = 0; for (elem <- data) { sum += elem } sum } /** * 函数的默认值 */ def Cli(ip:String,post:Int = 6379): String ={ ip+" "+post } /** * * 函数的递归 */ def digui(long: Long):Long = { if(long==1L){ return 1 }else{ long*digui(long-1) } } }