func sayHelloWorld() {
print("Hello World")
}
sayHelloWorld() // Hello World
func greet(person:String)->String {
return "Hello," + person + "!"
}
print(greet(person: "Roy")) // Hello,Roy!
func introduce(name:String,age:Int,gender:String) {
print("我的名字是: \(name) ,年龄: \(age),性别: \(gender)")
}
introduce(name: "Roy", age: 18, gender: "男")
func getMinandMaxValue(array:[Int])->(min:Int,max:Int) {
var currentMin = array[0]
var currentMax = array[0]
for value in array {
if value < currentMin {
currentMin = value
} else if value > currentMax {
currentMax = value
}
}
return (currentMin,currentMax)
}
let values = getMinandMaxValue(array: [8, -6, 2, 109, 3, 71])
print(values.min,values.max)
func introduce(name:String,age:Int,gender:String = "男") {
print("名字: \(name),年龄: \(age),性别: \(gender)")
}
introduce(name: "Roy", age:18 )
网友评论