总是记不住向方法中传数组参数的语法,所以记录一下。
func calculateStatistics(scores:[Int]) -> (min:Int,max:Int,sum:Int) { var min = scores[0] var max = scores[0] var sum = 0 for score in scores { if score>max { max=score } else if score<min{ min=score } sum += score } return (min,max,sum) } let a=calculateStatistics([5,3,100,3,9]) print(a.min) print(a.sum) print(a.0)
最主要的是这句:func calculateStatistics(scores:[Int]) -> (min:Int,max:Int,sum:Int) {}
时间: 2024-10-08 17:46:14