swift NO.2
// Playground - noun: a place where people can play
swift2.2 NO.2
import UIKit
var str = "Hello, playground"
let interestingNumbers=[
"Prime":[2,3,5,7,11,13],"Fibonacci":[1,1,2,3,5,8],"Square":[1,4,9,16,25]
]
var largest=0
for(kind ,numbers)in interestingNumbers {
for number in numbers
{
if number>largest {
largest=number
}
}
}
println(largest)
//
var n=2
while n<100{
n=n*2
}
print(n)
//
var total=0
for i in 0..<4 {
total+=i
}
println(total)
//
func greet(name:String,day:String)->String{
return "Hello \(name),today is \(day)."
}
greet("Bob ","Tuesday")
//
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 statistics=calculateStatistics([5,3,100,3,9])
println(statistics.sum)
println(statistics.2)