scala
object w29 {
def hello(name:String="小樊", age:Int, gender:String="女" ) = {
println(s"hello, 我是${name},${age}岁 , 性别:${gender}")
}
def main(args: Array[String]): Unit = {
hello("小胖",18,"男")
hello("小胖",18,"男")
hello("小胖",18)
hello(age=18)
}
}
scala
object w30 {
def getSum(args:Int*):Int = {
var sum = 0
for (i <- args){
sum += i
}
sum
}
def main(args: Array[String]): Unit = {
val result1 = getSum(1)
val result2 = getSum(4,1,2,3,5)
println(result1,result2)