首页 > 编程语言 > 详细

swift2.2 NO.2

时间:2016-03-02 00:17:32      阅读:192      评论:0      收藏:0      [点我收藏+]

// Playground - noun: a place where people can play

 

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)

// Playground - noun: a place where people can play

 

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)

// Playground - noun: a place where people can play

 

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)

// Playground - noun: a place where people can play

 

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)

swift2.2 NO.2

原文:http://www.cnblogs.com/yshgxm/p/5233321.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!