開発環境
- OS X Mavericks - Apple(OS)
- Xcode 6.0 Beta 6
- Swift (プログラミング言語)
Practical Programming: An Introduction to Computer Science Using Python 3 (Pragmatic Programmers) (Paul Gries (著)、Jennifer Campbell (著)、Jason Montojo (著)、Lynn Beighley (編集)、Pragmatic Bookshelf)のChapter 9(Repeating Code Using Loops)、9.10(Exercises) 4.をSwiftで考えてみる。
9.10(Exercises) 4.
コード(Xcode)
main.swift
// // main.swift // sample4 // // Created by kamimura on 9/5/14. // Copyright (c) 2014 kamimura. All rights reserved. // import Foundation println("a.") let alkaline_earth_metals = [[4, 9.012], [12, 24.305], [20, 40.078], [38, 87.62], [56, 137.327], [88, 226]] println(alkaline_earth_metals) println("b.") for metal in alkaline_earth_metals { println(metal[0]) println(metal[1]) } println("c.") var number_and_weight:[AnyObject] = [] for metal in alkaline_earth_metals { number_and_weight.append(metal[0]) number_and_weight.append(metal[1]) } println(number_and_weight)
入出力結果(Console Output)
a. [( 4, "9.012" ), ( 12, "24.305" ), ( 20, "40.078" ), ( 38, "87.62" ), ( 56, "137.327" ), ( 88, 226 )] b. 4 9.012 12 24.305 20 40.078 38 87.62 56 137.327 88 226 c. [4, 9.012, 12, 24.305, 20, 40.078, 38, 87.62, 56, 137.327, 88, 226] Program ended with exit code: 0
0 コメント:
コメントを投稿